matplotlib学习
figure, axes, axis, add_subplot, subplot
figure包括axes figure是画板,axes是画板上的子图
figure 使用add_subplot , pyplot使用的是subplot生成一个figure ,figure 里面再包含多个axes, axes 本质上是一个数组
pyplot有两个函数figure(figsize=指定画板大小)和subplot(nrows = , ncols,figsize=(大小)), fig = plt.figure(figsize=(12, 8)),
使用pyplot生成figure和指定数目axes
ax1, ax2, ax3, ax4 = ax.flatten() # flatten a 2d NumPy array to 1d
axes中相关参数的设置
ax.set_title(‘axes title’) 设置总体题目
ax.set_xlabel(‘xlabel’) 设置坐标x标签
ax.set_ylabel(‘ylabel’) 设置坐标y标签
ax.set_xlim([low,high]) 设置左边x的取值范围
ax.set_ylim([low,high]) 设置坐标y的取值范围
plt.figure(figsize=(8,6), dpi=80)
plt.subplot(111)
当figure中只有一个axes时,可以通过plt.set_xlim设置参数
A Figure object is the outermost container for a matplotlib graphic,
which can contain multiple Axes objects.
You can think of the Figure object as a box-like container holding one or more Axes (actual plots). Below the Axes in the hierarchy are smaller objects such as tick marks, individual lines, legends, and text boxes. Almost every “element” of a chart is its own manipulable Python object, all the way down to the ticks and labels:
Adding a legend,在图像中左上角上面增加一些标签