当前位置: 首页 > news >正文

Matplotlib:tick_params的用法

Matplotlib:tick_params 用于更改刻度、刻度标签和网格线的外观。

语法

Axes.tick_params(axis=‘both’, **kwargs)

参数:

Parameter Value Use
axis {‘ x ‘, ‘ y ‘, ‘ both ‘},可选 将参数应用于哪个轴。默认设置是“两个”。
reset bool,默认:False 如果为True,在处理其他关键字参数之前,将所有参数设置为默认值。
which 默认是“主要”;应用勾号的参数。
direction 将刻度置于坐标轴内、轴外,或同时置于两者。
length float 以点为单位的滴答长度。
width float 默认是“主要”;应用勾号的参数。
color 颜色 蜱虫的颜色。
pad float 标记和标签之间的点距离。
labelsize float或str 标记的字体大小以点表示或以字符串形式表示(e.g;,“大”)。

参数axis

参数axis的值为 ’ x’、‘y’、‘both’,分别代表设置X轴、Y轴以及同时设置,默认值为’both’。

import numpy as np
import matplotlib.pyplot as pltplt.subplot(131)
plt.tick_params(axis='x',width=4,colors='red')plt.subplot(132)
plt.tick_params(axis='y',width=4,colors='red')plt.subplot(133)
plt.tick_params(axis='both',width=4,colors='red')plt.show()

undefined

参数 which

参数which的值为 'major'、'minor'、'both',分别代表设置主刻度线、副刻度线以及同时设置,默认值为'major'

首先开启副刻度线plt.minorticks_on()

plt.subplot(131)
plt.minorticks_on()
plt.tick_params(which='major',width=2,colors='r')plt.subplot(132)
plt.minorticks_on()
plt.tick_params(which='minor',width=2,colors='r')plt.subplot(133)
plt.minorticks_on()
plt.tick_params(which='both',width=2,colors='r')plt.show()

在这里插入图片描述

参数direction

direction的值为'in'、'out'、'inout',分别代表刻度线显示在绘图区内侧、外侧以及同时显示

        plt.subplot(131)plt.minorticks_on()plt.tick_params(direction='in', width=2, length=4, colors='r')plt.subplot(132)plt.minorticks_on()plt.tick_params(direction='out', width=2, length=4, colors='r')plt.subplot(133)plt.minorticks_on()plt.tick_params(direction='inout', width=2, length=4, colors='r')plt.show()

在这里插入图片描述

参数 length和width

参数length和width分别用于设置刻度线的长度和宽度

plt.subplot(121)
plt.tick_params(width=4, colors='red')plt.subplot(122)
plt.tick_params(length=10,colors='red')plt.show()

在这里插入图片描述

参数 pad

参数pad用于设置刻度线与标签间的距离

plt.subplot(121)
plt.tick_params(pad=1, colors='red')plt.subplot(122)
plt.tick_params(pad=10,colors='red')plt.show()

在这里插入图片描述

参数color、labelcolor、colors

参数color、labelcolor、colors分别用于设置刻度线的颜色、刻度线标签的颜色以及同时设置刻度线及标签颜色

plt.subplot(131)
plt.tick_params(width=4,color='r')plt.subplot(132)
plt.tick_params(width=4,labelcolor='r')plt.subplot(133)
plt.tick_params(width=4,colors='r')plt.show()

在这里插入图片描述

参数 labelsize

参数labelsize用于设置刻度线标签的字体大小

plt.subplot(131)
plt.tick_params(labelsize='medium')plt.subplot(132)
plt.tick_params(labelsize='large')plt.subplot(133)
plt.tick_params(labelsize=15)plt.show()

在这里插入图片描述

参数bottom, top,left, right

参数bottom, top, left, right的值为布尔值,分别代表设置绘图区四个边框线上的的刻度线是否显示

plt.subplot(131)
plt.tick_params(bottom=False,top=True,width=4,colors='r')plt.subplot(132)
plt.tick_params(left=False,right=True,width=4,colors='r')plt.subplot(133)
plt.tick_params(top=True,right=True,width=4,colors='r')

在这里插入图片描述

参数labelbottom,labeltop, labelleft, labelright

参数labelbottom, labeltop, labelleft, labelright的值为布尔值,分别代表设置绘图区四个边框线上的刻度线标签是否显示

plt.subplot(131)
plt.tick_params(labelbottom=False,labeltop=True,width=4,colors='r')plt.subplot(132)
plt.tick_params(labelleft=False,labelright=True,width=4,colors='r')plt.subplot(133)
plt.tick_params(labeltop=True,labelright=True,width=4,colors='r')

在这里插入图片描述

参数 labelrotation

标签旋转

plt.subplot(121)
plt.tick_params(axis="x",labelrotation=60)plt.subplot(122)
plt.tick_params(axis="x",labelrotation=-60)

在这里插入图片描述

http://www.jsqmd.com/news/468791/

相关文章:

  • JAVA按模版导出Word文档(无需转换word格式)
  • 50个深蹲,就能练遍整个下半身!
  • 搜维尔科技:SenseGlove R1专为无缝控制人形机器人手而设计,融合了主动力反馈、毫米级手指追踪精度和振动触觉反馈
  • 2026年,济南联想信创服务器供应商究竟哪家强?最新评测为你揭晓答案!
  • the evilness of American English
  • 关于立交中辅助车道设置的探讨
  • PHP与C++:Web开发与系统编程的终极对决
  • python flask django露营研学基地服务管理系统
  • 自然语言处理实战与Ai辅助编程指南
  • # 发散创新:用CUDA+OpenMP实现异构计算在图像滤波中的高效加速 在现代高性能计
  • 营销智能体≠聊天机器人!搞清这三层,你的投入才不打水漂
  • linux 服务器设置 时 /etc/passwd设置为nologin时,登录SFTP会报 No supported authentication methods available
  • 简单绘制装修施工进度图在线画图工具操作便捷易上手
  • 源码交付赋能ISV:基于GB28181/RTSP的低代码AI视频平台二次开发实战
  • 深度解析安卓开发工程师职位:从技术栈到面试指南
  • PostgreSQL 入门学习教程,从入门到精通,PostgreSQL 16 数据备份与还原详解 —语法、案例与实战(16)
  • 深入Java中的YOLO实现:从Process调用到DJL NPU推理,工业级落地全流程
  • Ollama部署Qwen对接OpenClaw
  • 最近在折腾结构光三维重建,发现格雷码和相移这俩兄弟配合起来干活真挺有意思。今天咱们就手撕几段核心代码,看看怎么用Python把三维模型从二维图像里刨出来
  • 别再用人工/RFID盘点了!无人零售货架边缘计算实战:Java+YOLOv11s+WebSocket+RK3588,盘点准确率99.2%
  • 【重要概念】CRTP:奇异递归模板模式、零开销多态的编译期魔法
  • Android 应用架构演进与设计指南
  • k8s的service、ingress controller和ingress
  • Unity中使用矩阵实现物体跟随
  • 从Spring Boot到Quarkus:Java+YOLOv11边缘/云端部署双杀!启动快5倍、内存降60%、容器缩70%!
  • 气动力到载荷——BEM理论
  • 恒压供水(无负压供水)系统全图纸程序
  • 智慧调度:让光伏和储能系统共同编织绿色能源网
  • AI教材写作大揭秘:如何利用AI工具实现低查重优质产出!
  • 图片格式转换小技巧:BMP批量变PNG的5种方法分享