Python绘图常用

绘图(一) 坐标轴设置

1. 字体

plt.rc('font',family='Times New Roman')

2. 刻度设置

  • fontsize 字号
  • color 颜色
  • rotation 倾斜度
plt.xticks(fontsize=10,color='blue',rotation=60) 
plt.yticks(fontsize=10)

3. 坐标轴范围xlim/ylim

plt.xlim(0,100)
plt.ylim(10,20)

4. 坐标轴线

  • 粗细
ax=plt.gca();
ax.spines['bottom'].set_linewidth(1);
ax.spines['left'].set_linewidth(1);
  • 不显示坐标轴上面和右边刻度线
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')

或者

ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)

5. 坐标轴标签

plt.xlabel('X')            
plt.ylabel('Y')

6. 坐标轴刻度间隔

xmajorLocator   = MultipleLocator(10) 
xmajorFormatter = FormatStrFormatter('%1.1f') 
xminorLocator   = MultipleLocator(1) 

ymajorLocator   = MultipleLocator(0.05) # 主刻度以0.05为单位
ymajorFormatter = FormatStrFormatter('%1.1f') # 精确到小数点后一位
yminorLocator   = MultipleLocator(0.01) # 次刻度0.01为单位

ax=plt.gca()
ax.xaxis.set_major_locator(x_major_locator)
ax.xaxis.set_major_formatter(xmajorFormatter)
ax.xaxis.set_minor_locator(xminorLocator)

ax.yaxis.set_major_locator(y_major_locator)
ax.yaxis.set_major_formatter(ymajorFormatter)
ax.yaxis.set_minor_locator(yminorLocator)

#坐标轴的网格使用主刻度/次刻度设置
ax.xaxis.grid(True, which='major') # x主刻度
ax.yaxis.grid(True, which='minor') # y次刻度
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值