Questions tagged [savefig]

This tag is for questions related to saving figures in matplotlib with .savefig

matplotlib.pyplot.savefig

80 questions
318
votes
15 answers

Removing white space around a saved image

I need to take an image and save it after some process. The figure looks fine when I display it, but after saving the figure, I got some white space around the saved image. I have tried the 'tight' option for savefig method, did not work either. The…
Ahmet Tuğrul Bayrak
  • 3,466
  • 2
  • 15
  • 27
138
votes
6 answers

Saving plots (AxesSubPlot) generated from python pandas with matplotlib's savefig

I'm using pandas to generate a plot from a dataframe, which I would like to save to a file: dtf = pd.DataFrame.from_records(d,columns=h) fig = plt.figure() ax = dtf2.plot() ax = fig.add_subplot(ax) fig.savefig('~/Documents/output.png') It seems…
bhoward
  • 2,780
  • 4
  • 21
  • 22
114
votes
13 answers

scipy: savefig without frames, axes, only content

In numpy/scipy I have an image stored in an array. I can display it, I want to save it using savefig without any borders, axes, labels, titles,... Just pure image, nothing else. I want to avoid packages like PyPNG or scipy.misc.imsave, they are…
Jakub M.
  • 32,471
  • 48
  • 110
  • 179
90
votes
2 answers

Save a subplot in matplotlib

Is it possible to save (to a png) an individual subplot in a matplotlib figure? Let's say I have import pyplot.matplotlib as plt ax1 = plt.subplot(121) ax2 = plt.subplot(122) ax1.plot([1,2,3],[4,5,6]) ax2.plot([3,4,5],[7,8,9]) Is it possible to…
Robert Franke
  • 2,224
  • 2
  • 17
  • 10
35
votes
3 answers

Matplotlib savefig image trim

The following sample code will produce a basic line plot with no axes and save it as an SVG file: import matplotlib.pyplot as plt plt.axis('off') plt.plot([1,3,1,2,3]) plt.plot([3,1,1,2,1]) plt.savefig("out.svg", transparent = True) How do I set…
oden
  • 3,461
  • 1
  • 31
  • 33
32
votes
6 answers

Matplotlib savefig does not save axes

I'm trying to save a figure that works fine in IPython inline but does not save the figure to disk with the axes and titles included. I am using TKAgg backend by default in matplotlibrc. Any ideas what might be going wrong here? I have clearly set…
Richard Todd
  • 2,406
  • 5
  • 32
  • 40
11
votes
2 answers

Black background behind a figure's labels and ticks after saving figure, but not in Interactive view

I have a strange problem where if I save a figure, its labels and ticks will have a black background, see this example: plt.savefig("asdsadsad.png") I'm not even including any code here because this happens on the simplest plotting, even with code…
KMFR
  • 895
  • 1
  • 15
  • 24
6
votes
0 answers

Matplotlib.savefig ignoring axes and plotting black border around image

I have a matplotlib Figure embedded in a QtAggFigureCanvas (PyQt4) with titles and axis labels (example shown below). I implemented a button to save the figure to a png file. The figure was created with: self.plkDpi = 100 self.plkFigure =…
jcolen19
  • 318
  • 3
  • 11
6
votes
2 answers

Saving matplotlib subplot figure to image file

I'm fairly new to matplotlib and am limping along. That said, I haven't found an obvious answer to this question. I have a scatter plot I wanted colored by groups, and it looked like plotting via a loop was the way to roll. Here is my reproducible…
Hendy
  • 10,182
  • 15
  • 65
  • 71
5
votes
2 answers

Save an image (only content, without axes or anything else) to a file using Matloptlib

I'd like to obtain a spectrogram out of a wav file and then save it to a png, but I need just the content of the image (not axes or anything else). I came across these questions Matplotlib plots: removing axis, legends and white spaces scipy:…
Colonder
  • 1,556
  • 3
  • 20
  • 40
4
votes
1 answer

Save sklearn pipeline diagram

I want to save a pipeline displayed with the set_config(display="diagram") command, see below: Is there a better way to do it than by taking a screenshot?
Joris Limonier
  • 681
  • 1
  • 10
  • 27
3
votes
1 answer

Matplotlib not saving axes on savfig

This code only saves this image. As you can see it's rather empty :| Where are my axes plots? start = 100 sim_rets = gbm( mu=m.mu, n_scenarios=m.scenarios, n_years=m.years, prices=True, s_0=start, sigma=m.sigma, …
Michael Paccione
  • 2,467
  • 6
  • 39
  • 74
3
votes
1 answer

save subplots after .imshow()

Here are my visualization codes: f, ax = plt.subplots(1, 2) for i, img in enumerate([img1, img2]): grads = # my visualization codes # visualize grads as heatmap ax[i].imshow(grads, cmap='jet') How could I save whatever was shown using…
shenglih
  • 879
  • 2
  • 8
  • 18
2
votes
3 answers

Errors with savefig

All parts of Python on my computer were recently installed from the Enthought academic package, but use Pyscripter for editing and running code. I'm very early in my learning curve, and so could very well be overlooking some obvious things…
user1301991
  • 21
  • 1
  • 1
  • 2
2
votes
2 answers

x axis label cropped on saved image

So I'm trying to do a bar plot on a data where x is the username (string ) and each x is long enough to overlap each other, so I have to rotate the x label. No problem there. However, when exporting the plot results, the x label on the exported…
Yusuf Syam
  • 701
  • 1
  • 4
  • 18
1
2 3 4 5 6