Skip to content

Commit

Permalink
use cleanplotlib
Browse files Browse the repository at this point in the history
  • Loading branch information
nschloe committed Apr 29, 2020
1 parent ec3fef4 commit b02c5da
Showing 1 changed file with 23 additions and 29 deletions.
52 changes: 23 additions & 29 deletions stressberry/cli/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,40 @@


def plot(argv=None):
import cleanplotlib as cpl
import matplotlib.pyplot as plt

parser = _get_parser_plot()
args = parser.parse_args(argv)

data = [yaml.load(f, Loader=yaml.SafeLoader) for f in args.infiles]

# sort the data such that the data series with the lowest terminal
# temperature is plotted last (and appears in the legend last)
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(1, 1, 1)
for k in order[::-1]:
temperature_data = data[k]["temperature"]
a = []
b = []
c = []
for d in data:
temperature_data = d["temperature"]
if args.delta_t:
temperature_data = []
zip_object = zip(data[k]["temperature"], data[k]["ambient"])
for data[k]["temperature"], data[k]["ambient"] in zip_object:
temperature_data.append(data[k]["temperature"] - data[k]["ambient"])
ax1.plot(
data[k]["time"], temperature_data, label=data[k]["name"], lw=args.line_width
)
zip_object = zip(d["temperature"], d["ambient"])
for d["temperature"], d["ambient"] in zip_object:
temperature_data.append(d["temperature"] - d["ambient"])
a.append(d["time"])
b.append(temperature_data)
c.append(d["name"])

cpl.multiplot(a, b, c)

ax1.grid()
if not args.hide_legend:
ax1.legend(loc="upper left", bbox_to_anchor=(1.03, 1.0), borderaxespad=0)
if args.delta_t:
plot_yaxis_label = "Δ temperature °C (over ambient)"
plot_yaxis_label = "Δ temperature [°C over ambient]"
else:
plot_yaxis_label = "temperature °C"
ax1.set_xlabel("time (s)")
ax1.set_ylabel(plot_yaxis_label)
ax1.set_xlim([data[-1]["time"][0], data[-1]["time"][-1]])
plot_yaxis_label = "temperature [°C]"
cpl.xlabel("time [s]")
cpl.ylabel(plot_yaxis_label)

if args.temp_lims:
ax1.set_ylim(*args.temp_lims)

Expand All @@ -51,14 +50,13 @@ def plot(argv=None):
if args.freq_lims:
ax2.set_ylim(*args.freq_lims)
try:
for k in order[::-1]:
for d in data:
ax2.plot(
data[k]["time"],
data[k]["cpu frequency"],
label=data[k]["name"],
d["time"],
d["cpu frequency"],
label=d["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'
Expand Down Expand Up @@ -125,17 +123,13 @@ def _get_parser_plot():
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",
dest="transparent",
help="do not make images transparent",
action="store_false",
default=True,
)
parser.add_argument(
"-lw", "--line-width", type=float, default=None, help="line width"
)
parser.add_argument(
"--delta-t",
action="store_true",
Expand Down

0 comments on commit b02c5da

Please sign in to comment.