|
2 | 2 | # standard library imports |
3 | 3 | import os |
4 | 4 | from datetime import datetime |
| 5 | +from pathlib import Path |
| 6 | +import socket |
5 | 7 |
|
6 | 8 | # related third-party imports |
7 | 9 | import matplotlib.pyplot as plt |
8 | 10 | from PIL import Image |
9 | | -from pathlib import Path |
| 11 | +from tzlocal import get_localzone |
10 | 12 |
|
11 | 13 | # local application/library specific imports |
12 | 14 | # from xyfigure.xybase import XYBase |
@@ -186,11 +188,15 @@ def figure(self): |
186 | 188 | # https://github.com/matplotlib/matplotlib/issues/3173 |
187 | 189 | # https://matplotlib.org/3.1.1/tutorials/intermediate/imshow_extent.html |
188 | 190 | bounds = [left, right, bottom, top] |
189 | | - im = ax.imshow(im, zorder=0, extent=bounds, alpha=al, aspect="auto") |
| 191 | + im = ax.imshow( |
| 192 | + im, zorder=0, extent=bounds, alpha=al, aspect="auto" |
| 193 | + ) |
190 | 194 |
|
191 | 195 | for model in self._models: |
192 | 196 | # needs rearchitecting, a logview descends from a view |
193 | | - if self._xaxislog and not self._yaxislog: # needs rearchitecting |
| 197 | + if ( |
| 198 | + self._xaxislog and not self._yaxislog |
| 199 | + ): # needs rearchitecting |
194 | 200 | ax.semilogx(model.x, model.y, **model.plot_kwargs) |
195 | 201 | elif not self._xaxislog and self._yaxislog: |
196 | 202 | ax.semilogy(model.x, model.y, **model.plot_kwargs) |
@@ -249,14 +255,31 @@ def figure(self): |
249 | 255 | ax.legend() |
250 | 256 |
|
251 | 257 | if self._details: |
252 | | - now = datetime.now() |
253 | | - now_str = now.strftime("%Y-%m-%d %H:%M:%S") |
| 258 | + # Get the local timezone |
| 259 | + local_timezone = get_localzone() |
| 260 | + |
| 261 | + # Get the current time in the local timezone |
| 262 | + current_time = datetime.now(local_timezone) |
| 263 | + |
| 264 | + # Format the date and time stamp |
| 265 | + timestamp = current_time.strftime("%Y-%m-%d %H:%M:%S %Z%z") |
| 266 | + |
254 | 267 | user = str(os.getlogin()) |
255 | | - host = str(os.getenv("HOSTNAME")) |
| 268 | + # host = str(os.getenv("HOSTNAME")) |
| 269 | + host = socket.gethostname() |
256 | 270 | details_str = ( |
257 | | - self._file + " created " + now_str + " by " + user + " on " + host |
| 271 | + self._file |
| 272 | + + " created " |
| 273 | + + timestamp |
| 274 | + + " by " |
| 275 | + + user |
| 276 | + + " on " |
| 277 | + + host |
| 278 | + ) |
| 279 | + |
| 280 | + ax.set_title( |
| 281 | + details_str, fontsize=8, ha="center", color="dimgray" |
258 | 282 | ) |
259 | | - ax.set_title(details_str, fontsize=10, ha="center", color="dimgray") |
260 | 283 |
|
261 | 284 | if self._display: |
262 | 285 | plt.show() |
@@ -346,7 +369,9 @@ def figure(self): |
346 | 369 | xs, ys, _ = zip(*model._nodes) |
347 | 370 |
|
348 | 371 | for face in model._elements: |
349 | | - xf = tuple(xs[k - 1] for k in face) # 1-base index to 0-base index |
| 372 | + xf = tuple( |
| 373 | + xs[k - 1] for k in face |
| 374 | + ) # 1-base index to 0-base index |
350 | 375 | yf = tuple(ys[k - 1] for k in face) |
351 | 376 | # plt.fill( |
352 | 377 | # xf, |
|
0 commit comments