OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to show tickmarks when using whitegrid seaborn style

  • Thread starter Thread starter Pablo
  • Start date Start date
P

Pablo

Guest
I'm struggling to find how to show the tick marks on the x-axis when I enable the whitegrid seaborn style:

Code:
import datetime
import itertools
import random

import pandas as pd
import numpy as np
import seaborn as sns
from matplotlib import pyplot as plt
import matplotlib.dates as mdates

chronos = np.arange('2024-03-01', '2024-07-01',  dtype='datetime64[D]')

with sns.axes_style("whitegrid"):
    sns.set({'xtick.bottom': True, 'xtick.top': True, 'patch.edgecolor': 'b'})
    fig, ax = plt.subplots(figsize=(20, 4), layout='constrained')
    sns.barplot(    
        x=chronos, 
        y=[random.randint(0, 10) for _ in chronos],
        ax=ax,
        width=1,
    )
    ax.tick_params(
        axis='x', 
        rotation=30
    )
    ax.tick_params(axis="both", colors="black")
    ax.xaxis.set_major_locator(
        mdates.MonthLocator(
            interval=1, 
            bymonthday=1
        )
    )

code output

Without the style applied, the marks appear. I've looked at the docs but can't figure out which option is removing them.

How do i show the tick marks with the seaborn style enabled?
<p>I'm struggling to find how to <em>show</em> the tick marks on the x-axis when I enable the <code>whitegrid</code> seaborn style:</p>
<pre class="lang-py prettyprint-override"><code>import datetime
import itertools
import random

import pandas as pd
import numpy as np
import seaborn as sns
from matplotlib import pyplot as plt
import matplotlib.dates as mdates

chronos = np.arange('2024-03-01', '2024-07-01', dtype='datetime64[D]')

with sns.axes_style("whitegrid"):
sns.set({'xtick.bottom': True, 'xtick.top': True, 'patch.edgecolor': 'b'})
fig, ax = plt.subplots(figsize=(20, 4), layout='constrained')
sns.barplot(
x=chronos,
y=[random.randint(0, 10) for _ in chronos],
ax=ax,
width=1,
)
ax.tick_params(
axis='x',
rotation=30
)
ax.tick_params(axis="both", colors="black")
ax.xaxis.set_major_locator(
mdates.MonthLocator(
interval=1,
bymonthday=1
)
)

</code></pre>
<p><a href="https://i.sstatic.net/F0ycfeaV.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/F0ycfeaV.png" alt="code output" /></a></p>
<p>Without the style applied, the marks appear. I've looked at the <a href="https://seaborn.pydata.org/generated/seaborn.axes_style.html" rel="nofollow noreferrer">docs</a> but can't figure out which option is removing them.</p>
<p>How do i show the tick marks with the seaborn style enabled?</p>
 

Latest posts

Top