• matplotlib ax 与 刻度相关函数


    参考链接
    https://blog.csdn.net/weixin_34498545/article/details/112631706
    
    
    进行初始化
    
    plt.figure(figsize = (8,6))
    
    ax = plt.gca()

    调整坐标轴范围
    
    x轴
    ax.set_xlim()
    
    
    y轴
    ax.set_ylim()
    
    设置在 0 - 8 之间
    ax.set_xlim(0,8)
    
    ax.set_ylim(0,8)

    设置 x 轴 y 轴 标题
    ("内容",fontsize = ,color = ,alpha = , bbox = ,)
    
    
    ax.set_xlabel()
    
    
    ax.set_ylabel()
    
    
    参数示例
    
    ax.set_xlabel("X轴",fontsize = 14,color = 'b',alpha = 0.7,bbox=dict(boxstyle='round,pad=0.5', fc='yellow', ec='blue',lw=1 ,alpha=0.7))
    
    ax.set_ylabel("Y轴",fontsize = 14,color = 'b',alpha = 0.7,bbox=dict(boxstyle='round,pad=0.5', fc='yellow', ec='blue',lw=1 ,alpha=0.7))

    修改默认刻度文字
    (列表 , family = , fontsize = ,)
    
    ax.set_xticklabels()
    
    
    ax.set_yticklabels()
    
    
    ax.set_xticklabels(['A','B','C','D','E','F','G'])
    
    ax.set_yticklabels(['','','','','','',''],
    family = 'SimHei',fontsize = 14)

    突出主副刻度
    使用 tick_params 对刻度线进行调整
    
    tick_params(which = , length = , labelsize = ,)
    
    
    
    tick_params(which='major',length=8,labelsize=10)
    
    
    tick_params(which='minor',length=4)

     调整 坐标轴 刻度 距离

    
    默认刻度 locator
    
    位置 MultipleLocator
    
    样式 FormatStrFormatter
    
    
    from matplotlib.ticker import MultipleLocator, FormatStrFormatter
    
    
    xmajorLocator   = MultipleLocator(1)
    ax.xaxis.set_major_locator(xmajorLocator)
    
    ymajorLocator   = MultipleLocator(1)
    ax.yaxis.set_major_locator(ymajorLocator)
    
    xminorLocator   = MultipleLocator(0.25)
    ax.xaxis.set_minor_locator(xminorLocator)
    
    yminorLocator   = MultipleLocator(0.25)
    ax.yaxis.set_minor_locator(yminorLocator)
    
    
    MultipleLocator(1) 表示刻度之间的间隔为 1
    如果觉得文章不错,可以分享给其他人哟~
  • 相关阅读:
    git本地及远程分支回退
    Git怎样撤销一次分支的合并Merge
    git仓库迁移的两种解决方案
    【转】Linux下mysql操作
    Linux下tomcat相关操作
    Linux下top命令详解
    Linux下crontab详解
    Linux下mysql安装
    Linux下RPM包管理
    Linux下用户组、文件权限详解
  • 原文地址:https://www.cnblogs.com/hany-postq473111315/p/15202660.html
Copyright © 2020-2023  润新知