8 examples of 'matplotlib savefig' in Python

Every line of 'matplotlib savefig' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
36def savefig(save_as):
37 """Save the figure."""
38 plt.savefig(f"../figures/Fig1_{save_as}.pdf", dpi=600, bbox_inches='tight')
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

51def savefig(self,fileName):
52 self.fig.savefig(fileName)
94def save_figure(filename, extra_artists=None, tight=True):
95 filename = filename.replace('.', '-')
96 filename += '.pdf'
97 if extra_artists:
98 plt.savefig(
99 FIGURES_DIR + filename,
100 bbox_extra_artists=extra_artists,
101 bbox_inches='tight')
102 else:
103 if tight:
104 plt.tight_layout()
105 plt.savefig(FIGURES_DIR + filename)
70def render_mpl(self, fig, path, **kwargs):
71 return fig.savefig(path, format=self.name, **kwargs)
925def savefig(title):
926 # today = datetime.now().strftime('%Y-%m-%d')
927
928 # Lowercase, replace special chars with whitespace, join on whitespace.
929 cleantitle = '-'.join(re.sub('[^a-z0-9]+', ' ', title.lower()).split())
930
931 fname = cleantitle
932 fpath_cmd = fname + '.command'
933
934 log.info('Writing command to %s', fpath_cmd)
935 command = poor_mans_cmdline()
936 with open(fpath_cmd, 'w') as f:
937 f.write(command)
938
939 log.info('Writing figure as PNG to %s', fname + '.png')
940 plt.savefig(fname + '.png', dpi=200)
137def save_figure(filename, fig=None):
138 """Apply the figure options for saving and then save the supplied
139 figure to ``filename``.
140
141 The format of the output figure is set by ``options.plotting_outtype``.
142
143 **Parameters:**
144
145 filename : string
146 The output filename.
147 fig : figure object, optional
148 The figure to be saved.
149
150 **Returns:**
151
152 ``None``.
153 """
154 if fig is None:
155 fig = pylab.gcf()
156 fig.set_size_inches(*options.plotting_save_figsize)
157 pylab.savefig(filename, dpi=100, bbox_inches='tight',
158 format=options.plotting_outtype, pad=0.1)
159 fig.set_size_inches(*options.plotting_display_figsize)
1425def save_figure(
1426 figure, save_at="", name="fig", save_fmts=["png"], output=False, **kwargs
1427):
1428 """
1429 Save a figure at a specified location in a number of formats.
1430 """
1431 default_config = dict(dpi=600, bbox_inches="tight", transparent=True)
1432 config = default_config.copy()
1433 config.update(kwargs)
1434 for fmt in save_fmts:
1435 out_filename = os.path.join(str(save_at), name + "." + fmt)
1436 if output:
1437 logger.info("Saving " + out_filename)
1438 figure.savefig(out_filename, format=fmt, **config)
4def ggsave(plot, filename, width=None, height=None):
5 plot.make()
6 w, h = plot.fig.get_size_inches()
7 if width:
8 w = width
9 if height:
10 h = height
11 plot.fig.set_size_inches(w, h)
12 plot.fig.savefig(filename)

Related snippets