python matplotlib 画图归类(持续更新)

  1. 所有坐标轴显示刻度:
    plt.tick_params(top='on', right='on', which='both')
  2. 主刻度和次刻度都朝里:
    ax.tick_params(direction='in',which='both')
  3. 设置y轴刻度值标签旋转90°:
    • 方法一
      ax.tick_params(axis='y', rotation=90)
    • 方法二 – 遇到了有的版本(比如anaconda3/lib/python3.5/site-packages/matplotlib)报错没有关键词 “labelrotation” 或 “rotation ” 的使用以下方式:
      for tick in ax.get_yticklabels():
          tick.set_rotation(90)
      
  4. 设置坐标轴刻度标签大小:
    ax.tick_params(labelsize=14)
  5. 不显示刻度和刻度值标签:
    ax.set_xticks([])
    显示刻度,但不显示刻度值标签:
    ax.set_xticklabels([])
  6. 将纵轴刻度值的中心与刻度对应
    for label in ax.get_yticklabels():
        label.set_verticalalignment('center')
    
  7. 设置刻度
    from matplotlib.ticker import (MultipleLocator, AutoMinorLocator,MaxNLocator)
    • 100为单位的主刻度
      ax.yaxis.set_major_locator(MultipleLocator(100))
    • 20为单位的次刻度
      ax.yaxis.set_minor_locator(MultipleLocator(20))
    • 共设置四个刻度
      ax.yaxis.set_major_locator(MaxNLocator(4))
画图常用
import matplotlib
from matplotlib.ticker import (MultipleLocator, AutoMinorLocator)

ax.set_xlim([1/float(NBIN)*360-180,NBIN/float(NBIN)*360-180])
ax.minorticks_on()
ax.set_xticklabels([])
ax.set_xlabel("Longitude ($^\circ$)",fontsize=14)
ax.set_ylabel("Norm. I",fontsize=14)
ax.tick_params(axis='y', rotation=90)
ax.tick_params(top=True,right=True,direction='in',which='both',labelsize=14)

ax.text(0.04,0.94,textT,rotation='horizontal',horizontalalignment='left',verticalalignment='top',transform=ax.transAxes,fontsize=13,linespacing=1.6)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值