plt绘图细节调整

import matplotlib.pyplot as plt
import pandas as pd
from pandas import DataFrame

df = DataFrame([[1,5,3,4],
                [4,1,2,1],
                [2,2,3,4],
                [2,3,2,1],
                [1,3,4,2],
                [3,3,2,1]],
               index=['03-02','03-03','03-04','03-05','03-06','03-07'],
               columns=pd.Index(['#709DF7','#73DEB3','#7585A2','#F7C739'],name='name'))
# 创建画布
fig, ax = plt.subplots()
# 绘图
df.plot(kind='bar',ax=ax,color=['#709DF7','#73DEB3','#7585A2','#F7C739'],title="趋势")
# 标题设置
plt.rcParams['font.sans-serif'] = ['SimHei'] # 正常显示中文
ax.set_title("趋势(本月)",fontsize=10,color="#666")
# 修改x轴y周的字体颜色倾斜度
ax.set_xlabel('日期',color="#666")
ax.set_ylabel('数字',color="#666")
ax.xaxis.set_tick_params(rotation=45,labelsize=10,colors="#666")
ax.yaxis.set_tick_params(labelsize=10,colors="#666")
# 修改边框颜色
ax.spines['bottom'].set_color('#666')
ax.spines['top'].set_color('none')
ax.spines['left'].set_color('#666')
ax.spines['right'].set_color('none') # 无色
# 设置图例字号颜色
labels = ax.legend(fontsize=10,framealpha=0.1).get_texts()
[label.set_color('#666') for label in labels]
# 标注
ax.annotate("最高点", #标注内容
            xy=(0,5), # 箭头顶部 标注坐标点
            xytext=(0,5.5), # 箭头下方以及标注文字位置
            arrowprops=dict(facecolor='#999',width=4,headwidth=8), # 箭头颜色,样式
            horizontalalignment='left',
            verticalalignment='top')
# 显示
plt.show()

 

posted @ 2021-09-10 12:06  OTAKU_nicole  阅读(177)  评论(0编辑  收藏  举报