其他分享
首页 > 其他分享> > 几种常用作图

几种常用作图

作者:互联网

做热图

import seaborn as sns;
sns.set()
plt.figure(dpi=400)
ax1 = sns.heatmap(A,cmap="YlGnBu",vmin=-0.8,vmax=0.8,annot=True,fmt=".2f",annot_kws={'size':5})

plt.title('H0_1')
plt.show()
    

直方图

    x = np.arange(20)
    total_width, n = 0.8, 2
    width = total_width / n
    x = x - (total_width - width) / 2
    plt.barh(x, e2, height=width, label='e3')
    plt.barh(x + width, e2, height=width, label='e4')
    plt.xlabel("energy")
    plt.legend()
    plt.show()

误差图

    x = np.array([100, 1000, 10000, 100000,1000000])
    dy = np.array([0.046882158,0.007782108,0.004341331,0.001801209,0.00024765])
    y = np.array([0.596939253, 0.093611854, 0.013429654, 0.002950581, 0.000327617])

    plt.axes(yscale="log",xscale="log")  # 双log坐标系
    # plt.errorbar(x, y, yerr=dy, fmt='o', ecolor='r', color='b', elinewidth=2, capsize=4)
    
    for x1, y1 in zip(x, y): # 给每个点备注数值
        plt.text(x1, y1 + 0.01, '%.2e' % y1, ha='center', va='bottom', fontsize=9)
    #.2e表示科学计数法,保留2位。正常是.2d 保留两位小数

    plt.title("title")
    plt.ylabel("Y")
    plt.xlabel("X")
    plt.show()

标签:常用,plt,y1,show,作图,title,几种,width,np
来源: https://blog.csdn.net/qq_41667567/article/details/121069720