Skip to content

Commit

Permalink
Plot line width configurable.
Browse files Browse the repository at this point in the history
Legend can be hidden.
Frquency axis range can be specified.
Temperature plot, topmost (z-order fix)
Plot output image transparency configurable
  • Loading branch information
shortbloke committed Sep 5, 2019
1 parent f109870 commit ac70189
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -10,3 +10,4 @@ build/
*.dat
*.png
.pytest_cache/
.vscode/
52 changes: 44 additions & 8 deletions stressberry/cli.py
Expand Up @@ -159,34 +159,55 @@ def plot(argv=None):
terminal_temps = [d["temperature"][-1] for d in data]
order = [i[0] for i in sorted(enumerate(terminal_temps), key=lambda x: x[1])]
# actually plot it
fig = plt.figure()
ax1 = fig.add_subplot()
for k in order[::-1]:
plt.plot(data[k]["time"], data[k]["temperature"], label=data[k]["name"])
ax1.plot(
data[k]["time"],
data[k]["temperature"],
label=data[k]["name"],
lw=args.line_width,
)

plt.grid()
plt.legend(loc="upper left", bbox_to_anchor=(1.03, 1.0), borderaxespad=0)
plt.xlabel("time (s)")
plt.ylabel("temperature (°C)")
plt.xlim([data[-1]["time"][0], data[-1]["time"][-1]])
ax1.grid()
if not args.hide_legend:
ax1.legend(loc="upper left", bbox_to_anchor=(1.03, 1.0), borderaxespad=0)
ax1.set_xlabel("time (s)")
ax1.set_ylabel("temperature (°C)")
ax1.set_xlim([data[-1]["time"][0], data[-1]["time"][-1]])
if args.temp_lims:
plt.ylim(*args.temp_lims)
ax1.set_ylim(*args.temp_lims)

# Only plot frequencies when using a single input file
if len(data) == 1 and args.frequency:
ax2 = plt.twinx()
ax2.set_ylabel("core frequency (MHz)")
if args.freq_lims:
ax2.set_ylim(*args.freq_lims)
try:
for k in order[::-1]:
ax2.plot(
data[k]["time"],
data[k]["cpu frequency"],
label=data[k]["name"],
color="C1",
alpha=0.9,
lw=args.line_width,
)
ax1.set_zorder(ax2.get_zorder() + 1) # put ax1 plot in front of ax2
ax1.patch.set_visible(False) # hide the 'canvas'
except KeyError():
print("Source data does not contain CPU frequency data.")

if args.outfile is not None:
plt.savefig(args.outfile, transparent=True, bbox_inches="tight", dpi=args.dpi)
if args.not_transparent:
plt.savefig(
args.outfile, transparent=False, bbox_inches="tight", dpi=args.dpi
)
else:
plt.savefig(
args.outfile, transparent=True, bbox_inches="tight", dpi=args.dpi
)
else:
plt.show()
return
Expand Down Expand Up @@ -232,4 +253,19 @@ def _get_parser_plot():
help="plot CPU core frequency (single input files only)",
action="store_true",
)
parser.add_argument(
"-l",
"--freq-lims",
type=float,
nargs=2,
default=None,
help="limits for the frequency scale (default: data limits)",
)
parser.add_argument("--hide-legend", help="do not draw legend", action="store_true")
parser.add_argument(
"--not-transparent", help="do not draw legend", action="store_true"
)
parser.add_argument(
"-lw", "--line-width", type=float, default=None, help="line width"
)
return parser

0 comments on commit ac70189

Please sign in to comment.