Skip to content

Commit cb2498a

Browse files
authored
Merge pull request #2 from max-models/1-get-the-format-from-the-filename-when-saving
Remove extension from savefig
2 parents 66b91cb + 252c1b0 commit cb2498a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/maxplotlib/canvas/canvas.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
import matplotlib.pyplot as plt
24
import plotly.graph_objects as go
35
from plotly.subplots import make_subplots
@@ -120,11 +122,12 @@ def add_subplot(self, **kwargs):
120122
def savefig(
121123
self,
122124
filename,
123-
extension="pdf",
124125
backend="matplotlib",
125126
layers=None,
126127
layer_by_layer=False,
128+
verbose=False,
127129
):
130+
filename_no_extension, extension = os.path.splitext(filename)
128131
if backend == "matplotlib":
129132
if layer_by_layer:
130133
layers = []
@@ -133,17 +136,21 @@ def savefig(
133136
fig, axs = self.plot(
134137
show=False, backend="matplotlib", savefig=True, layers=layers
135138
)
136-
fig.savefig(f"{filename}_{layers}.{extension}")
139+
_fn = f"{filename_no_extension}_{layers}.{extension}"
140+
fig.savefig(_fn)
141+
print(f"Saved {_fn}")
137142
else:
138143
if layers is None:
139144
layers = self.layers
140-
full_filepath = f"{filename}.{extension}"
145+
full_filepath = filename
141146
else:
142-
full_filepath = f"{filename}_{layers}.{extension}"
147+
full_filepath = f"{filename_no_extension}_{layers}.{extension}"
143148
fig, axs = self.plot(
144149
show=False, backend="matplotlib", savefig=True, layers=layers
145150
)
146151
fig.savefig(full_filepath)
152+
if verbose:
153+
print(f"Saved {full_filepath}")
147154

148155
def plot(self, backend="matplotlib", show=True, savefig=False, layers=None):
149156
if backend == "matplotlib":

0 commit comments

Comments
 (0)