How to decrease the density of x-ticks in Seaborn?


To decrease the density of x-ticks in Seaborn, we can use set_visible=False for odd positions.

Steps

  • Set the figure size and adjust the padding between and around the subplots.

  • Create a dataframe with X-axis and Y-axis keys.

  • Show the point estimates and confidence intervals with bars, using barplot() method.

  • Iterate bar_plot.get_xticklabels() method. If index is even, then make them visible; else, not visible.

  • To display the figure, use show() method.

Example

import pandas
import matplotlib.pylab as plt
import seaborn as sns
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
df = pandas.DataFrame({"X-Axis": [i for i in range(10)], "Y-Axis": [i for i in range(10)]})
bar_plot = sns.barplot(x='X-Axis', y='Y-Axis', data=df)
for index, label in enumerate(bar_plot.get_xticklabels()):
   if index % 2 == 0:
      label.set_visible(True)
   else:
      label.set_visible(False)
plt.show()

Output

Updated on: 01-Jun-2021

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements