python - matplotlib pie charts leave labels from previous pie chart -
i have small django app produces 2 different pie charts. labels first chart that's displayed reappear in second chart.
i'm using:
plt.pie(...) plt.savefig(...) in same view 2 different pie charts using 2 different (small) datasets.
is there 'clear' or 'reset' method need call after saving of plot?
you can leave code unchanged, , clean figure calling clf() after having saved first plot , before generating second plot.
by doing so, interfacing matplotlib state-machine. matplotlib automatically creates figure , axes you, , use keep using same figure.
the alternative use matplotlib in more object-oriented way. ask matplotlib create figure , axes object, , rest calling methods of objects:
fig1,ax1=plt.subplots() fig2,ax2=plt.subplots() ax1.pie(...) ax2.pie(...) fig1.savefig(...) fig2.savefig(...) the usage faq here clarifies 2 options.
Comments
Post a Comment