very good tutorial
matplotlib和PIL打开图片的方法
command
- figure
- size 12plt.figure(figsize=(20,10)) # this command shall be at beginning.<!-- more -->
Based on ref matplotlib.pyplot.figure, the default size of a plot is 6.4 and 4.8.
rcParams["figure.figsize"] = [6.4, 4.8]
-
subplots size
fig, ax1 = plt.subplots(figsize=(20, 10))
如果不用上面的命令,而用ax.figure.set_size_inches(50,10)
,不好使。 -
other thins
plt.figure(dpi=80, facecolor='w', edgecolor='w')
-
line
plt.plot(X, C, color="blue", linewidth=1.0, linestyle="-", label="balala data", marker='tri', markersize=3,)
-
limit (range)
plt.xlim(-4.0,4.0)
-
legend
plt.legend(loc='upper left')
-
ticks
plt.xticks(np.linspace(-4,4,9,endpoint=True))
-
label of axis
plt.xlabel("This is X axis")
-
save/load
- save
plt.savefig("name.png")
Note thatplt.show()
will clean the content, sosavefig
should be in front - load
12img = mpimg.imread("3732video_star_distri.png")plt.imshow(img) - save
-
histogram
plt.hist(mydict.values(), bins=10)
-
add additional ticks
123456lines = plt.plot(x,y)ax = lines[0].axeslim = ax.get_ylim()ax.set_yticks(list(ax.get_yticks()) + extraticks_list)ax.set_ylim(lim)
ref: adding extra axis ticks using matplotlib
-
arrow
plt.arrow(datetime(2018,4,21), 1.268, 30, 0, linestyle=(0,(5,10)))
注意:是(x,y,dx,dy),第三个和第四个参数是箭头的长度;这里30被当做30天;(offset,(onoffseq))格式的参考可见:linestyle -
add x2 axis
ax2 = ax1.twinx()
ref: example code
concept
- axes
Figure > axes
ref: What is ‘axes’(NOTE: not ‘axis’) - plot vs. subplot vs. figure.add_subplot()
ref: What is the difference between drawing plots using plot, axes or figure in matplotlib?
global setting
|
|
- font 12345font = {'family' : 'normal','weight' : 'bold','size' : 22}matplotlib.rc('font', **font)