Python saving empty plot

Osama Arshad Dar

EDIT: This question is a duplicate. Original question's link is posted above.

I am using Python to plot a set of values which are showing good on the Python terminal (using Jupyter NoteBook) but when I save it, the saved file when opened shows an empty (completely white) photo. Here's my code:

import matplotlib.pyplot as plt
plt.plot([1,3,4])
plt.show()
plt.savefig('E:/1.png')
Reblochon Masque

You should save the plot before closing it: indeed, plt.show() dislays the plot, and blocks the execution until after you close it; hence when you attempt to save on the next instruction, the plot has been destroyed and can no longer be saved.

import matplotlib.pyplot as plt
plt.plot([1,3,4])
plt.savefig('E:/1.png')   # <-- save first
plt.show()                # <-- then display

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Matplotlib: Check for empty plot

分類Dev

Bokeh plot is empty

分類Dev

Why does this render an empty plot?

分類Dev

Saving Slope Coefficients in Python

分類Dev

Saving json response in python

分類Dev

GNUplot batch plotting producing empty plot files

分類Dev

geom_rect gives empty plot with no rectangle

分類Dev

bokeh plot empty when rendering Flask template

分類Dev

try plotting an iteration but plt.plot is empty

分類Dev

Saving zip file in python to disk

分類Dev

Stripping empty attributes from Laravel model before saving

分類Dev

Recurrence plot in python

分類Dev

Plot curves instead of bar plot using python

分類Dev

python split empty string

分類Dev

Saving statmodels Tukey hsd into a Python pandas dataframe

分類Dev

Multiprocessing a python for loop and saving results as a dictionary

分類Dev

Saving variables in Python as columns without brackets

分類Dev

saving the number into the variable in every run of cycle python

分類Dev

Python: Saving / loading large array using numpy

分類Dev

Python: Error saving output into csv file?

分類Dev

Plot empty markers in y vs x plot with colors according to z values

分類Dev

Python: Multiple QQ-Plot

分類Dev

Not able to plot using plotly in python

分類Dev

Multiple updating plot with pyqtgraph in Python

分類Dev

How to run two function from same resource(plot graphic and saving infinite data to txt file)

分類Dev

How to plot simple plot from DataFrame in Python Pandas?

分類Dev

Python: pop from empty list

分類Dev

Python logging creates empty files

分類Dev

Python writes empty json file