Matplotlib (pyplot) savefig outputs blank image
First, what happens when T0 is not None
? I would test that, then I would adjust the values I pass to plt.subplot()
; maybe try values 131, 132, and 133, or values that depend whether or not T0
exists.
Second, after plt.show()
is called, a new figure is created. To deal with this, you can
Call
plt.savefig('tessstttyyy.png', dpi=100)
before you callplt.show()
Save the figure before you
show()
by callingplt.gcf()
for "get current figure", then you can callsavefig()
on thisFigure
object at any time.
For example:
fig1 = plt.gcf()
plt.show()
plt.draw()
fig1.savefig('tessstttyyy.png', dpi=100)
In your code, 'tesssttyyy.png' is blank because it is saving the new figure, to which nothing has been plotted.
Matplotlib savefig exporting as blank image in colab
Ola @devman3211 o/
I'm a Google Colab user too :)
Have you check if the plot respect your condition?
If yes, try to change
not sharpened_image is None
forsharpened_image is not None
.
You have to respect a certain order of priority, update your code considering the following:
#first generate your plot
fig1 = plt.imshow(#whatever you want to plot)
#then save it
plt.savefig('test.png', dpi=1000)
#finally .show() or .draw() it in this order
plt.show()
plt.draw()
Proof of work:
Result (for fun):
Matplotlib .savefig results in empty image
You must save it writing plt.savefig('path.pdf')
BUT before plt.show()
. I think it will work. Tell me.
pyplot saving blank image and plt.show() not working
Tried replicating your code in colab, It indeed works fine when run in a single cell.
The reason for getting blank output while segregating the code into different cells is:
The plot is generated as soon as the cell comprising plt.axis
is run.
After that, all operations are done on the axis, whose axis? Is not specified so a new plotting window is created (this gives a blank plot).
I would advise you to run the plotting statements in a single cell, as colab shows output as soon as something related to matplotlib is run thereby making the axis of previous plot inaccessible. And all subsequent operations are run on a fresh figure.
plt.savefig saves a blank image
Well if you want to fix your problem input this in your code. I don't know exactly why it happens but it is fixed by this plt.show() should come before plt.savefig()
Explanation: plt.show() clears the whole thing, so anything afterwards will happen on a new empty figure.
fig1 = plt.gcf()
plt.show()
plt.draw()
fig1.savefig(y_train, y_dev, y_test, y, plot_data_stripplot_distplot, dpi=100)
plt.savefig produces blank figure in Python
Try using the Figure object directly.
fig=plt.figure()
plt.plot(x,y)
fig.savefig('line_plot.png', dpi=100)
If you are interested in a PNG use '.png' instead of '.jpg'. Depending on the GUI toolkit you may need to add fig.show() before the last line.
Related Topics
How to Convert a Nested Python Dict to Object
Differencebetween a String and a Byte String
Python Dictionary: Are Keys() and Values() Always the Same Order
Create Own Colormap Using Matplotlib and Plot Color Scale
Writing a Python List of Lists to a CSV File
Get Rows Based on Distinct Values from One Column
Settingwithcopywarning Even When Using .Loc[Row_Indexer,Col_Indexer] = Value
How to Rotate an Image Around an Off Center Pivot in Pygame
Running Unittest with Typical Test Directory Structure
Is It Worth Using Python's Re.Compile
Creating a Range of Dates in Python
How to Use Python Requests to Fake a Browser Visit A.K.A and Generate User Agent
How to One Hot Encode in Python
Executable Python Program with All Dependencies for Linux
Detect Specific Keypresses in Gui