Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
618 views
in Technique[技术] by (71.8m points)

matplotlib ticks thickness

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)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

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,...)

Take a look at set_tick_params doc and tick_params valid keywords


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...