Skip to content

Commit 1b50734

Browse files
committed
Don't plot if plotted
1 parent e99e6dc commit 1b50734

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/maxplotlib/backends/matplotlib/utils_old.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def scale_axis(
419419

420420
if not axs_in == None:
421421
ax = axs_in
422-
print("precision", precision, precision, precision)
422+
# print("precision", precision, precision, precision)
423423
plt.sca(ax)
424424
if axis == "x":
425425
if locs_labels == None:
@@ -520,7 +520,7 @@ def add_figure_label(
520520
ax=None,
521521
):
522522
limits = self.get_limits(ax)
523-
print(limits)
523+
# print(limits)
524524
lx = limits[1] - limits[0]
525525
ly = limits[3] - limits[2]
526526

src/maxplotlib/canvas/canvas.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def __init__(self, **kwargs):
3333
self._width = kwargs.get("width", "17cm")
3434
self._ratio = kwargs.get("ratio", "golden")
3535
self._gridspec_kw = kwargs.get("gridspec_kw", {"wspace": 0.08, "hspace": 0.1})
36+
self._plotted = False
3637

3738
# Dictionary to store lines for each subplot
3839
# Key: (row, col), Value: list of lines with their data and kwargs
@@ -126,6 +127,7 @@ def savefig(
126127
layers=None,
127128
layer_by_layer=False,
128129
verbose=False,
130+
plot=True,
129131
):
130132
filename_no_extension, extension = os.path.splitext(filename)
131133
if backend == "matplotlib":
@@ -145,10 +147,16 @@ def savefig(
145147
full_filepath = filename
146148
else:
147149
full_filepath = f"{filename_no_extension}_{layers}.{extension}"
148-
fig, axs = self.plot(
149-
show=False, backend="matplotlib", savefig=True, layers=layers
150-
)
151-
fig.savefig(full_filepath)
150+
print(f"Save to {full_filepath}")
151+
if self._plotted:
152+
self._matplotlib_fig.savefig(full_filepath)
153+
else:
154+
155+
fig, axs = self.plot(
156+
show=False, backend="matplotlib", savefig=True, layers=layers
157+
)
158+
print('done plotting')
159+
fig.savefig(full_filepath)
152160
if verbose:
153161
print(f"Saved {full_filepath}")
154162

@@ -166,7 +174,7 @@ def plot_matplotlib(self, show=True, savefig=False, layers=None, usetex=False):
166174
filename (str, optional): Filename to save the figure.
167175
show (bool): Whether to display the plot.
168176
"""
169-
177+
print(f"Plotting with maxplotlib ")
170178
tex_fonts = plt_utils.setup_tex_fonts(fontsize=self.fontsize, usetex=usetex)
171179

172180
plt_utils.setup_plotstyle(
@@ -198,6 +206,7 @@ def plot_matplotlib(self, show=True, savefig=False, layers=None, usetex=False):
198206

199207
for (row, col), subplot in self.subplots.items():
200208
ax = axes[row][col]
209+
print(f"subplot.plot_matplotlib(ax, layers=layers)")
201210
subplot.plot_matplotlib(ax, layers=layers)
202211
# ax.set_title(f"Subplot ({row}, {col})")
203212
ax.grid()
@@ -208,6 +217,9 @@ def plot_matplotlib(self, show=True, savefig=False, layers=None, usetex=False):
208217
plt.show()
209218
# else:
210219
# plt.close()
220+
self._plotted = True
221+
self._matplotlib_fig = fig
222+
self._matplotlib_axes = axes
211223
return fig, axes
212224

213225
def plot_plotly(self, show=True, savefig=None, usetex=False):

0 commit comments

Comments
 (0)