Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No major tick marks showing using seaborn white style and cannot restore

When I generate plots using the seaborn "white" style I see major tick labels but I don't see any major tick marks.

Setting major tick marks to be bigger using...

%matplotlib inline

import seaborn as sns
import matplotlib.pyplot as plt

sns.set_style('white', {'axes.linewidth': 0.5})
plt.rcParams['xtick.major.size'] = 20
plt.rcParams['xtick.major.width'] = 4

fig, ax = plt.subplots()
plt.show()

...has no effect.

I can't find any option that would make the tick marks visible/invisible.

Anybody have any clues?

like image 431
Ymareth Avatar asked Oct 18 '18 10:10

Ymareth


People also ask

Can ticks change color?

Ticks are easier to identify once they are done feeding because their body becomes engorged. The scutum remains the same size, but the body will become larger and change color once feeding is complete. The colors range from brownish red to pale gray or greenish grey.

How do you change the color of a tick in Python?

To set the color for X-axis and Y-axis, we can use the set_color() method (Set both the edgecolor and the facecolor). To set the ticks color, use tick_params method for axes. Used arguments are axis ='x' (or y or both) and color = 'red' (or green or yellow or ...etc.)

How do you remove a tick in Seaborn?

Use left=false and bottom=false to remove the tick marks.


2 Answers

The rcParams 'xtick.major.size' and 'xtick.major.width' can indeed be used to change the length and width of the ticks. The rcParams 'xtick.bottom' and 'ytick.left' can be used to set the ticks on or off.

import seaborn as sns
import matplotlib.pyplot as plt

sns.set_style('white', {'axes.linewidth': 0.5})
plt.rcParams['xtick.major.size'] = 20
plt.rcParams['xtick.major.width'] = 4
plt.rcParams['xtick.bottom'] = True
plt.rcParams['ytick.left'] = True

fig, ax = plt.subplots()
plt.show()

enter image description here

like image 176
ImportanceOfBeingErnest Avatar answered Oct 19 '22 11:10

ImportanceOfBeingErnest


In case one wants to not mess with global rcParams, but manually tune by plot, one can use ax.tick_params()

import seaborn as sns
import matplotlib.pyplot as plt

sns.set_style('white', {'axes.linewidth': 0.5})

fig, ax = plt.subplots()
ax.tick_params(bottom=True, left=True)
plt.show()

The critical part is "enabling" the tick marks - in this case the bottom and left marks were enabled. If one wants marks on the four sides, using ax.tick_params(reset=True) might also be an option, though I'm not sure how this might affect other Seaborn tunings.

There are also a number of options listed in the function documentation that might be useful, although they do not apply directly to OP.

Note: this answer also works for other styles, including the default one, not just 'white'.

like image 1
Ronan Paixão Avatar answered Oct 19 '22 13:10

Ronan Paixão