Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I used matplotlib, but the error message '<Figure size 720x576 with 0 Axes>' appeared with graph

import matplotlib.pyplot as plt
from matplotlib import font_manager, rc

f_name = font_manager.FontProperties(fname='C:/Windows/Fonts/HANBatangExt.ttf').get_name()
rc('font', family=f_name)

뛰기운동

plt.plot(run_before, run_after, 'ro-')

걷기운동

plt.plot(walk_before, walk_after, 'bo-')
plt.figure(figsize=((10,8)))
plt.show()
like image 622
정채원 Avatar asked Oct 16 '18 11:10

정채원


People also ask

How do I fix the size of a figure in Python?

Using figurepyplot. figure that is used to create a new figure or activate an existing one. The method accepts an argument called figsize that is used to specify the width and height of the figure (in inches). Additionally, you can even specify dpi that corresponds to the resolution of the figure in dots-per-inch.

Why is matplotlib not working?

Occasionally, problems with Matplotlib can be solved with a clean installation of the package. In order to fully remove an installed Matplotlib: Delete the caches from your Matplotlib configuration directory. Delete any Matplotlib directories or eggs from your installation directory.


1 Answers

It is not an error but the output you see is due to the fact that you have used

plt.figure(figsize=((10,8)))

after plt.plot. Therefore, you first get a figure on you screen and a figure object is created by plt.figure. To get rid of it, you should first set the figure size before plotting, something like this:

plt.figure(figsize=((10,8)))
plt.plot(run_before, run_after, 'ro-')
plt.plot(walk_before, walk_after, 'bo-')
plt.show()

There are other ways to set the figure size after plotting but since your code is fine enough, you are good to go with the above modification.

like image 70
Sheldore Avatar answered Sep 25 '22 22:09

Sheldore