多子图画图数据标签只堆在一个子图中怎么解决呀

讨论 1356号炼丹师
Lv1 居士
发布在 Matplotlib   774   1
讨论 1356号炼丹师   774   1

多子图画图数据标签堆在一个子图中

如图

代码如下:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus'] = Falseplt.figure(figsize=(8,10), dpi=100)
plt.figure(1)plt.tight_layout()data=pd.read_excel(r'D:\资料下载\月报\月报数据\月报数据.xlsx','省公司-月份-检测应用数')
data=data.fillna(-1)
ax = plt.subplot(3,2,1)
ax1 = plt.subplot(3,2,2)
ax2 = plt.subplot(3,2,3)
ax3 = plt.subplot(3,2,4)
ax4 = plt.subplot(3,2,5)
ax5 = plt.subplot(3,2,6)
# 创建图实例
x = data.iloc[:,0]
label=list(data)
col=data.shape[1]
for i in range(1, int(col / 6) + 1):
    ax.plot(x, data.iloc[:, i], label=label[i])
    for a, b in zip(x, data.iloc[:, i]):
        plt.text(a, b + 0.05, '%.0f' % b, ha='center', va='bottom', fontsize=9)
for m in range(int(col / 6)+1, int(col / 3) + 1):
    ax1.plot(x, data.iloc[:, m], label=label[m])
    for a, b in zip(x, data.iloc[:, m]):
        plt.text(a, b + 0.05, '%.0f' % b, ha='center', va='bottom', fontsize=9)
for n in range(int(col / 3)+1, int(col / 2) + 1):
    ax2.plot(x, data.iloc[:, n], label=label[n])
    for a, b in zip(x, data.iloc[:, n]):
        plt.text(a, b + 0.05, '%.0f' % b, ha='center', va='bottom', fontsize=9)
for o in range(int(col / 2)+1, int(col*2 / 3) + 1):
    ax3.plot(x, data.iloc[:, o], label=label[o])
    for a, b in zip(x, data.iloc[:, o]):
        plt.text(a, b + 0.05, '%.0f' % b, ha='center', va='bottom', fontsize=9)
for p in range(int(col*2 / 3)+1, int(col*5 / 6) + 1):
    ax4.plot(x, data.iloc[:, p], label=label[p])
    for a, b in zip(x, data.iloc[:, p]):
        plt.text(a, b + 0.05, '%.0f' % b, ha='center', va='bottom', fontsize=9)
for q in range(int(col*5 / 6) + 1, int(col) ):
    ax5.plot(x, data.iloc[:, q], label=label[q])
    for a, b in zip(x, data.iloc[:, q]):
        plt.text(a, b + 0.05, '%.0f' % b, ha='center', va='bottom', fontsize=9)
ax.set_ylabel('检测应用数')#设置y轴名称 y label
ax.set_title('省公司检测应用数') #设置图名为Simple Plot
ax.legend() #自动检测要在图例中显示的元素,并且显示
ax1.set_title('省公司检测应用数') #设置图名为Simple Plot
ax1.legend() #自动检测要在图例中显示的元素,并且显示
ax2.set_ylabel('检测应用数') #设置y轴名称 y label
ax2.legend() #自动检测要在图例中显示的元素,并且显示
ax3.legend() #自动检测要在图例中显示的元素,并且显示
ax4.set_xlabel('月份') #设置x轴名称 x label
ax4.set_ylabel('检测应用数') #设置y轴名称 y label
ax4.legend() #自动检测要在图例中显示的元素,并且显示
ax5.set_xlabel('月份') #设置x轴名称 x label
ax5.legend() #自动检测要在图例中显示的元素,并且显示
plt.show()
plt.tight_layout()
版权声明:作者保留权利,不代表意本站立场。如需转载请联系本站以及作者。

参与讨论

回复《 多子图画图数据标签只堆在一个子图中怎么解决呀

EditorJs 编辑器

沙发,很寂寞~
反馈
to-top--btn