Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9143813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:07:01+00:00 2026-06-17T10:07:01+00:00

I have a generic plotting class that uses matplotlib to generate (png) plots that

  • 0

I have a generic plotting class that uses matplotlib to generate (png) plots that may have multiple y axis, but always a single (shared) x-axis that shows dates.

This is the method that deals with x axis label formatting:

def format_xaxis(self, axis, primary):
    steps = (1,2,3,4,6,12)
    step = steps[min(len(self.dates) // 1000, 5)]
    axis.set_axisbelow(True)
    axis.xaxis.grid(b=True, which='minor', color='0.90', linewidth=0.5)
    axis.xaxis.set_minor_locator(MonthLocator(bymonth=range(1,13,step)))
    axis.xaxis.set_major_locator(YearLocator())
    if primary:
        axis.xaxis.set_major_formatter(DateFormatter(fmt='%b %y'))
        axis.xaxis.set_minor_formatter(DateFormatter(fmt='%b'))
    else:
        plt.setp(axis.get_xticklabels(), visible=False)

with input:

  • primary is a boolean that indicates if this is the primary axis
  • axis is a matplotlib axis instance

What I want (and expect from the above method) is that the only the primary axis has labels and that the major labels are month-year and the minor labels month only.

What happens is that only major labels are shown on the primary axis, minor labels are not shown at all.

If I change the last 6 lines to:

    axis.xaxis.set_major_locator(YearLocator())
    axis.xaxis.set_major_formatter(DateFormatter(fmt='%b %y'))
    axis.xaxis.set_minor_formatter(DateFormatter(fmt='%b'))
    if not primary:
        plt.setp(axis.get_xticklabels(), visible=False)

then minor labels are shown on all axes.

How can I show minor x-axis tick labels on the primary x-axis only?

EDIT:

Using KevinG’s suggestion on the 2nd code block works:

    axis.xaxis.set_major_locator(YearLocator())
    axis.xaxis.set_major_formatter(DateFormatter(fmt='%b %y'))
    axis.xaxis.set_minor_formatter(DateFormatter(fmt='%b'))
    if not primary:
        plt.setp(axis.get_xticklabels(minor=False), visible=False)
        plt.setp(axis.get_xticklabels(minor=True), visible=False)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:07:02+00:00Added an answer on June 17, 2026 at 10:07 am

    I noticed that a lot of the tick label stuff has minor=False as default arguments. Without having a multiple axis plot handy right now, I can only suggest you look there. I imagine something like

    if primary:
        axis.xaxis.set_major_formatter(DateFormatter(fmt='%b %y'))
        axis.xaxis.set_minor_formatter(DateFormatter(fmt='%b'))
        plt.setp(axis.get_xticklabels(minor=True), visible=True)
    else:
        plt.setp(axis.get_xticklabels(), visible=False)
    

    should have some effect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have generic type that looks like: public class GenericClass<T, U> where T :
I have a Generic Base Class that I want to allow one of two
I'm writing a couple of classes that all have generic type arguments, but I
Have a generic class that inherits from a non-generic class like the structure below:
I want to write in Delphi (2009 - so I have generic dictionary class)
I am aware of Web Services and WCF but I have generic question with
I have a generic linked-list that holds data of type void* I am trying
I have a generic Print method that iterates over a list and simply prints
I would like to build a generic class that I can use to implement
I have generic classes that look like: interface X<Input, Output> { Output process(Input input);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.