常用图
基本要素
使用风格模板
# plt.style.use(['ieee'])
全局参数定义
rc={'font.family':"Times New Roman",
'mathtext.fontset':'stix',
'font.size':8}
matplotlib.rcParams.update(rc)
子图调整
plt.subplots_adjust(wspace=0.1,hspace=0.1)
设置小标题文字
ax[0].text(.03,.9,"(a)",transform = ax[0].transAxes,fontdict=text_font2,zorder=4)
图例设置
fig=plt.figure(figsize=(7,2),dpi=300)
ax = fig.subplots(ncols=3,nrows=1,sharey=True)
# 以fig为对象画全局图例
b,legend=fig.axes[2].get_legend_handles_labels()
# bbox_to_anchor=(0.33,0.9) 设置图例位置
fig.legend(legend,bbox_to_anchor=(0.33,0.9))
y轴设置
import matplotlib.ticker as mtick
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
ymajorLocator = MultipleLocator(0.004)
ax[0][1].yaxis.set_major_locator(ymajorLocator)
ax[0][1].set_ylim([0.016,0.036])
ax[0][1].yaxis.set_major_formatter(mtick.FormatStrFormatter('%.3f'))
常用图
雷达图
ax = plt.subplot(131,polar=True)
ax.plot(angles, score_a,color='g',lw=0.5)
#角度设置
angles = np.linspace(0, 2*np.pi, data_length, endpoint=False)[::-1]+np.pi/3
#标签设置
ax.set_thetagrids(angles*180/np.pi, labels)
#设置起始位置
ax.set_theta_zero_location('N')
#设置外圈数值
ax.set_rlim(0, 2.5)
#设置标签位置
ax.set_rlabel_position(200)
热力图
#"orientation":"horizontal" 横放colormap
sns.heatmap(data3,ax=ax[2][0],cmap='summer',cbar_kws={"orientation":"horizontal","shrink":1})
#colorbar 设置
cbar = ax2.collections[0].colorbar
cbar.ax.set_xlim([0.048,0.059])
密度图
import seaborn as sns
#denisty表示只显示密度曲线
sns.histplot(err,stat='density',color='#5799c6',ax=ax[0])
Q-Q图
import statsmodels.api as sm
fig1=sm.qqplot(data=err1,line='s',ax=ax[1],marker="o",c='b',markersize=2.0,lw=1.0)
包裹图
ax.fill_between(np.arange(0,len(data1_true[:,0])),data1_99[:,0],data1_99[:,1],alpha=1,color='#ccf2f2',label='99% interval')