matplotlib
工欲善其事,必先利其器
At the beginning of this month, in the morning of deadline for VLDB, I got stuck for hours just to draw “good” figures for our experiment parts. The reason is that I haven’t used Matlab for quit a long time, so I totally forgot many things. As a lesson, I think I need to write down some notes here. Since Matlab really gave me awful experience, I decide to turn to python.
First of all, we need numpy and matplotlib.
Acually, what I need are just 2D bars and lines. So I would just keep nodes for these two. we use pyplot, which provides a MATLAB-like plotting framework.
Talk is cheap, show me your code.
bar
1 | import numpy as np |
Then we could generate the following figure.
so as you can see, it is just like Matlab. pyplot provides
xlabel
,ylabel
,title
xticks
,yticks
figsize
,savefig
legend
figsize
specify the width and height of figure, and the default DPI is 80. While the default DPI forsavefig
is 100. so if you want to makeplt.show()
andplt.savefig
look identical, you could passfig.dpi
tosavefig
.fig.savefig('temp.png', dpi=fig.dpi)