matpltolib fig,ax坐标轴,多子图,主标题

https://blog.csdn.net/htuhxf/article/details/82986440

fig = plt.figure() 参数

matpltlib.pyplot.figure( num
= None, # 设定figure名称。系统默认按数字升序命名的figure_num(透视表输出窗口) figsize=None, # 设定figure尺寸。系统默认命令是rcParams["figure.fig.size"] = [6.4, 4.8] dpi=None, # 设定figure像素密度。系统默命令是rcParams["sigure.dpi"] = 100 facecolor=None, # 设定figure背景色。系统默认命令是rcParams["figure.facecolor"] = 'w',白色 edgecolor=None, frameon=True, # 设定要不要绘制轮廓&轮廓颜色。系统默认绘制轮廓,轮廓染色rcParams["figure.edgecolor"]='w',白色; FigureClass=<class 'matplotlib.figure.Figure'>, # 设定使不使用一个figure模板。系统默认不使用; clear=False, # 设定当同名figure存在时,是否替换它。系统默认False,即不替换。 **kwargs)
创建多维窗口

fig, axes = plt.subplots(2, 2) 
pd.Series 对象可以通过 plot.bar 函数绘制柱状图


data = pd.Series(可迭代对象,index = ,)
data.plot.bar(ax= ,, color= , alpha= ,)


data = pd.Series(np.random.rand(4), index=list('abcd'))
 
data.plot.bar(ax=axes[1,1], color='b', alpha = 0.5)

fig, ax1 = plt.subplots(1, 1)             
# 做1*1个子图,等价于  fig, ax1 = plt.subplot() 
# 等价于  fig, ax1 = plt.subplots() 



ax2 = ax1.twinx()                         
# 让2个子图的x轴一样,同时创建副坐标轴。
不显示图表框


ax.spines['top'].set_visible(False)                   
# 不显示图表框的上边框


ax.spines['right'].set_visible(False)                 
# 不显示图表框的右边框
plt.xticks(range(0, 10), fontsize=12, rotation=80)    

# 对x轴的标签,指定范围是(0, 10), 字体大小是12, 逆时针旋转80°

plt.tick_params(bottom='off', left='off', labelbottom='on')  
# 使x轴和y轴不带比例标识点,
# labelbottom设定下边、即x轴的标签是否显示。

设置子图主标题
plt.suptitle 参数


matplotlib.pyplot.suptitle(
t,                          # text缩写。即标题文字。
fontsize | size,            # 设定字体大小。
x,                          # 设定标题相对于x轴的位置,默认是'0.5'。
y,                          # 设定标题相对于y轴的位置,默认是'0.98'。
ha | horizontalalignment,   # 和参数x一起使用,设定标题水平方位,默认是‘center’。共3个可选值{'center', 'left', right'}。
va | verticalalignment,     # 和参数y一起使用,设定标题垂直方位, 默认是'top'。共4个可选值{'top', 'center', 'bottom', 'baseline'}。
fontweight | weight         # 设定字体权重。
)

如果觉得文章不错,可以分享给其他人哟~
原文地址:https://www.cnblogs.com/hany-postq473111315/p/15202810.html