Verified Commit eb39450e authored by Sebastian Endres's avatar Sebastian Endres
Browse files

Fix plot margins / cutted-off labels

parent 0bc2e7d6
......@@ -326,7 +326,7 @@ class PlotCli:
def plot_offset_number(self, output_file: Optional[Path]):
"""Plot the offset number diagram."""
with Subplot(nrows=1, ncols=1) as (_fig, ax):
with Subplot(nrows=1, ncols=1) as (fig, ax):
ax.grid(True)
ax.set_xlabel("Time (s)")
ax.set_ylabel("Offset")
......@@ -461,11 +461,11 @@ class PlotCli:
)
self._annotate_time_plot(ax, height=max_offset, spinner=spinner)
self._save(output_file, spinner)
self._save(fig, output_file, spinner)
def plot_packet_number(self, output_file: Optional[Path]):
"""Plot the packet number diagram."""
with Subplot(nrows=1, ncols=1) as (_fig, ax):
with Subplot(nrows=1, ncols=1) as (fig, ax):
ax.grid(True)
ax.set_xlabel("Time (s)")
ax.set_ylabel("Packet Number")
......@@ -555,11 +555,12 @@ class PlotCli:
)
self._annotate_time_plot(ax, height=max_packet_number, spinner=spinner)
self._save(output_file, spinner)
spinner.write(f"rtt: {self.traces[0].extended_facts.get('rtt')}")
self._save(fig, output_file, spinner)
def plot_file_size(self, output_file: Optional[Path]):
"""Plot the file size diagram."""
with Subplot() as (_fig, ax):
with Subplot() as (fig, ax):
ax.grid(True)
ax.set_xlabel("Time (s)")
ax.set_ylabel("Transmitted File Size")
......@@ -631,7 +632,7 @@ class PlotCli:
)
self._annotate_time_plot(ax, height=max_file_size, spinner=spinner)
self._save(output_file, spinner)
self._save(fig, output_file, spinner)
def _process_packet_sizes(self):
"""Helper function."""
......@@ -672,7 +673,7 @@ class PlotCli:
def plot_packet_size(self, output_file: Optional[Path]):
"""Plot the packet size diagram."""
with Subplot() as (_fig, ax):
with Subplot() as (fig, ax):
ax.grid(True)
ax.set_xlabel("Time (s)")
ax.set_ylabel("Packet Size")
......@@ -756,7 +757,7 @@ class PlotCli:
self._annotate_time_plot(ax, height=packet_stats.max, spinner=spinner)
self._save(output_file, spinner)
self._save(fig, output_file, spinner)
# def plot_packet_hist(self, output_file: Optional[Path]):
# """Plot the packet size histogram."""
......@@ -858,13 +859,20 @@ class PlotCli:
# ),
# )
#
# self._save(output_file, spinner)
# self._save(fig, output_file, spinner)
def _save(self, output_file: Optional[Path], spinner: YaspinWrapper):
def _save(
self, figure: plt.Figure, output_file: Optional[Path], spinner: YaspinWrapper
):
"""Save or show the plot."""
if output_file:
plt.savefig(output_file, dpi=300, transparent=True)
figure.savefig(
output_file,
dpi=300,
# transparent=True,
bbox_inches="tight",
)
spinner.text = colored(
f"{create_relpath(output_file)} written.", color="green"
)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment