Sonu Mishra
Sonu Mishra

Reputation: 1779

How to save Matplotlib.pyplot.loglog to file?

I am trying to generate the log-log plot of a vector, and save the generated plot to file.

This is what I have tried so far:

import matplotlib.pyplot as plt
... 
plt.loglog(deg_distribution,'b-',marker='o')
plt.savefig('LogLog.png')

I am using Jupyter Notebook, in which I get the generated graph as output after statement 2 in the above code, but the saved file is blank.

Upvotes: 1

Views: 625

Answers (1)

SparkAndShine
SparkAndShine

Reputation: 17997

Notice that pyplot has the concept of the current figure and the current axes. All plotting commands apply to the current axes. So, make sure you plot in the right axes. Here is a WME.

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.loglog(range(100), 'b-',marker='o')

plt.savefig('test.png')     # apply to the axes `ax`

Upvotes: 1

Related Questions