python matplotlib设置

标题设置

plt.title("销售趋势图", fontdict={'family':'Microsoft YaHei', 'color': 'k', 'size': 15}, loc='left')

坐标轴设置

坐标轴标签

plt.xlabel("月份", fontdict={'family':'Microsoft YaHei', 'color': 'k', 'size': 12}, labelpad=10)
plt.ylabel("销售额(万元)", fontdict={'family':'Microsoft YaHei', 'color': 'k', 'size': 12}, labelpad=10)

坐标轴范围

plt.ylim(50, 300)
plt.xlim(100,300)

图例设置

plt.legend(loc='best', fontsize=12) # best:matplotlib根据图表自动选择最优位置

数据标签设置

x = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
y1 = [123, 145, 152, 182, 147, 138, 189, 201, 203, 211, 201, 182]
y2 = [102, 121, 138, 154, 171, 178, 199, 231, 228, 202, 231, 271]

for a, b, c in zip(x, y1, y2):
    plt.text(a, b, b, va='bottom', fontdict={"size":14})
    plt.text(a, c, c, va='top', fontdict={"size":14})

网格线设置

参数b为True时展示网格线,axis支持x、y、both三个值,分别表示展示纵向网格线,横向网格线和纵向横向都展示;

plt.grid(b=True, axis='y', linestyle='--', linewidth=1, color='grey')

风格设置

要在画布之前设置

[‘Solarize_Light2’, ‘_classic_test_patch’, ‘bmh’, ‘classic’, ‘dark_background’, ‘fast’, ‘fivethirtyeight’, ‘ggplot’, ‘grayscale’, ‘seaborn’, ‘seaborn-bright’, ‘seaborn-colorblind’, ‘seaborn-dark’, ‘seaborn-dark-palette’, ‘seaborn-darkgrid’, ‘seaborn-deep’, ‘seaborn-muted’, ‘seaborn-notebook’, ‘seaborn-paper’, ‘seaborn-pastel’, ‘seaborn-poster’, ‘seaborn-talk’, ‘seaborn-ticks’, ‘seaborn-white’, ‘seaborn-whitegrid’, ‘tableau-colorblind10’]

plt.style.use(['ggplot'])
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值