Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib ticks thickness

Tags:

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) 

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

like image 545
user1850133 Avatar asked Feb 05 '13 10:02

user1850133


People also ask

How do I make the ticks bold in matplotlib?

Matplotlib x-axis label boldPass the fontweight parameter to the xlabel() function to make the label bold. We import the matplotlib.

What are major and minor ticks in matplotlib?

Demonstrate how to use major and minor tickers. The two relevant classes are Locator s and Formatter s. Locators determine where the ticks are, and formatters control the formatting of tick labels.

What are ticks in matplotlib?

Ticks are the markers denoting data points on axes. Matplotlib has so far - in all our previous examples - automatically taken over the task of spacing points on the axis. Matplotlib's default tick locators and formatters are designed to be generally sufficient in many common situations.


2 Answers

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

like image 104
tacaswell Avatar answered Sep 25 '22 01:09

tacaswell


You can change all matplotlib defaults using rcParams like in

import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt  # set tick width mpl.rcParams['xtick.major.size'] = 20 mpl.rcParams['xtick.major.width'] = 4 mpl.rcParams['xtick.minor.size'] = 10 mpl.rcParams['xtick.minor.width'] = 2  x = np.linspace(0., 10.) plt.plot(x, np.sin(x))  plt.show() 
like image 21
David Zwicker Avatar answered Sep 25 '22 01:09

David Zwicker