Note that there are some explanatory texts on larger screens.

plurals
  1. POHiding major tick labels while showing minor tick labels in matplotlib
    primarykey
    data
    text
    <p>I would like to hide the major tick labels on my x-axis while retaining just its minor labels. The idea is that my dates are displayed in between the major ticks instead of on them by default. I have seen a few other answers to similar questions as this one and tried using their way of hiding the major ticks however I am not having much luck getting it working at all. My graph currently looks like this:</p> <p><img src="https://i.stack.imgur.com/f4QAk.png" alt="Major and minor ticks for November"></p> <p>This is the formatting code I originally had for my graph before I decided I wanted to put the labels on the minor ticks.</p> <pre><code>day_fmt = '%d' myFmt = mdates.DateFormatter(day_fmt) ax.xaxis.set_major_formatter(myFmt) ax.xaxis.set_major_locator(matplotlib.dates.DayLocator(interval=1)) </code></pre> <p>I have attempted to get the minor ticks to show up while hiding major ticks using the code below. Here I've used an hour locator at 12pm to get the middle point of a day:</p> <pre><code>import matplotlib.ticker ax.xaxis.set_major_formatter(ticker.NullFormatter()) #Clear major tick labels ax.xaxis.set_minor_formatter(myFmt) ax.xaxis.set_minor_locator(matplotlib.dates.HourLocator(interval=12)) </code></pre> <p>But for some reason I get graphs that look like the picture above - with both major and minor x-axis tick labels. I also tried clearing unwanted ticks using <code>ax.set_xticks([])</code>. Has anyone had similar issues and fixed this or know a way to overcome this? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload