1.全局更改图表外观
plt.style.use("ggplot")
2.全局更改图片内的字体/可每次画图都重新定义一下个性化
plt.rc('font',family='Times New Roman', size=20)
3. 画竖直排列的柱状图
def visualization(namelist,numlist ,topath): fig, ax = plt.subplots(figsize=(30, 20)) ax.bar(x=namelist, height=numlist) ax.set_title(c_name, fontsize=30) plt.xticks(rotation = 90) # 让标签旋转90度竖直排列 plt.savefig(topath,bbox_inches = 'tight') # 保存图片时候不截断超出范围的label
4. 画折线图
def plot_curve(namelist,numlist ,topath): # 设置图表标题和标签 plt.figure(dpi=300,figsize=(16,8)) # 图片分辨率与大小比例设置 plt.title('Proportion of Research Topics in Computer Vision') plt.xlabel('Year') plt.ylabel('Proportion') # 设置图例 legend = namelist # 绘制折线图 for key, values in namelist,numlist: plt.plot([2021, 2022, 2023], values, label=key) # 显示图例 plt.legend(legend) plt.legend(bbox_to_anchor=(0.5, -0.2),loc=8,ncol=10) # 将图例显示在图表的正下方 # 显示图表 plt.show() plt.savefig(topath,bbox_inches = 'tight')
标签:topath,namelist,plt,画图,matplotlib,图例,可视化,legend,numlist From: https://www.cnblogs.com/traceofMind/p/17823504.html