MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / savefig

Method savefig

lib/matplotlib/figure.py:3360–3515  ·  view source on GitHub ↗

Save the current figure as an image or vector graphic to a file. Call signature:: savefig(fname, *, transparent=None, dpi='figure', format=None, metadata=None, bbox_inches=None, pad_inches=0.1, facecolor='auto', edgecolor='auto', backe

(self, fname, *, transparent=None, **kwargs)

Source from the content-addressed store, hash-verified

3358 self._axobservers.connect("_axes_change_event", lambda arg: func(arg))
3359
3360 def savefig(self, fname, *, transparent=None, **kwargs):
3361 """
3362 Save the current figure as an image or vector graphic to a file.
3363
3364 Call signature::
3365
3366 savefig(fname, *, transparent=None, dpi='figure', format=None,
3367 metadata=None, bbox_inches=None, pad_inches=0.1,
3368 facecolor='auto', edgecolor='auto', backend=None,
3369 **kwargs
3370 )
3371
3372 The available output formats depend on the backend being used.
3373
3374 Parameters
3375 ----------
3376 fname : str or path-like or binary file-like
3377 A path, or a Python file-like object, or
3378 possibly some backend-dependent object such as
3379 `matplotlib.backends.backend_pdf.PdfPages`.
3380
3381 If *format* is set, it determines the output format, and the file
3382 is saved as *fname*. Note that *fname* is used verbatim, and there
3383 is no attempt to make the extension, if any, of *fname* match
3384 *format*, and no extension is appended.
3385
3386 If *format* is not set, then the format is inferred from the
3387 extension of *fname*, if there is one. If *format* is not
3388 set and *fname* has no extension, then the file is saved with
3389 :rc:`savefig.format` and the appropriate extension is appended to
3390 *fname*.
3391
3392 Other Parameters
3393 ----------------
3394 transparent : bool, default: :rc:`savefig.transparent`
3395 If *True*, the Axes patches will all be transparent; the
3396 Figure patch will also be transparent unless *facecolor*
3397 and/or *edgecolor* are specified via kwargs.
3398
3399 If *False* has no effect and the color of the Axes and
3400 Figure patches are unchanged (unless the Figure patch
3401 is specified via the *facecolor* and/or *edgecolor* keyword
3402 arguments in which case those colors are used).
3403
3404 The transparency of these patches will be restored to their
3405 original values upon exit of this function.
3406
3407 This is useful, for example, for displaying
3408 a plot on top of a colored background on a web page.
3409
3410 dpi : float or 'figure', default: :rc:`savefig.dpi`
3411 The resolution in dots per inch. If 'figure', use the figure's
3412 dpi value.
3413
3414 format : str
3415 The file format, e.g. 'png', 'pdf', 'svg', ... The behavior when
3416 this is unset is documented under *fname*.
3417

Callers 15

imsaveFunction · 0.95
thumbnailFunction · 0.95
_repr_png_Method · 0.95
math_to_imageFunction · 0.95
test_unicode_wonFunction · 0.95
test_empty_lineFunction · 0.95
test_not_visible_figureFunction · 0.95
test_long_pathFunction · 0.95
innerFunction · 0.95
wrapperFunction · 0.95

Calls 1

print_figureMethod · 0.45

Tested by 8

test_unicode_wonFunction · 0.76
test_empty_lineFunction · 0.76
test_not_visible_figureFunction · 0.76
test_long_pathFunction · 0.76
innerFunction · 0.76
test_inset_axes_tightFunction · 0.36