matplotlib滴答厚度 [英] matplotlib ticks thickness

查看:75
本文介绍了matplotlib滴答厚度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以增加matplotlib中的刻度线的厚度和大小,而不必编写像这样的长代码:

Is there a way to increase the thickness and size of ticks in matplotlib without having to write a long piece of code like this:

for line in ax1.yaxis.get_ticklines():
    line.set_markersize(25)
    line.set_markeredgewidth(3)

这段代码的问题是它使用了一个循环,通常会占用大量CPU使用率.

The problem with this piece of code is that it uses a loop which costs usually a lot of CPU usage.

推荐答案

一种简单的方法是使用axis对象的set_tick_params函数:

A simpler way is to use the set_tick_params function of axis objects:

ax.xaxis.set_tick_params(width=5)
ax.yaxis.set_tick_params(width=5)

以这种方式进行操作意味着您可以在每个轴的基础上进行更改,而不必担心全局状态,也无需对mpl对象的内部结构进行任何假设.

Doing it this way means you can change this on a per-axis basis with out worrying about global state and with out making any assumptions about the internal structure of mpl objects.

如果要为所有轴上的刻度线设置此项,

If you want to set this for all the ticks in your axes,

ax = plt.gca()
ax.tick_params(width=5,...)

看看 set_tick_params 文档和 tick_params有效关键字

这篇关于matplotlib滴答厚度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆