Skip to content

matplotlibrc: new entry for placing y-axis tick label on Right or Left hand side. #10267

Closed

Description

@esvhd

Hi,

I understand that currently there is a way to place y-axis tick labels on the right hand side instead of the left by default, by calling ax.yaxis.tick_right().

See this SO post This is obviously very useful for people who study time series and latest values are sometimes more important than older values.

I'd like to suggest making that a profile setting in matplotlibrc. Open to dicussion here.

Thanks.

Activity

  1. jklymak commented on Jan 20, 2018

    @jklymak
    Member

    I think a PR along these lines would be welcome. Might as well do xlabel as well..

  2. esvhd commented on Jan 21, 2018

    @esvhd
    ContributorAuthor
  3. esvhd commented on Jan 21, 2018

    @esvhd
    ContributorAuthor

    @jklymak, I did some work on this, a quick solution to y-axis tick labels:

    1. Two new properties in matplotlibrc:
    ytick.labelleft : True
    ytick.labelright : False
    
    1. Add these in matplotlib.rcsetup.py so that these properties are recognized:
    'ytick.labelleft':   [True, validate_bool],
    'ytick.labelright':  [False, validate_bool],
    
    1. Make use of these properties in matplotlib.axes._base._AxesBase.__init__():
    self.tick_params(
                top=rcParams['xtick.top'] and rcParams['xtick.minor.top'],
                bottom=rcParams['xtick.bottom'] and rcParams['xtick.minor.bottom'],
                left=rcParams['ytick.left'] and rcParams['ytick.minor.left'],
                right=rcParams['ytick.right'] and rcParams['ytick.minor.right'],
                labelleft=rcParams['ytick.labelleft'] and rcParams['ytick.minor.left'],   # new here
                labelright=rcParams['ytick.labelright'] and rcParams['ytick.minor.right'],  # new here
                which='minor')
    
    self.tick_params(
                top=rcParams['xtick.top'] and rcParams['xtick.major.top'],
                bottom=rcParams['xtick.bottom'] and rcParams['xtick.major.bottom'],
                left=rcParams['ytick.left'] and rcParams['ytick.major.left'],
                right=rcParams['ytick.right'] and rcParams['ytick.major.right'],
                labelleft=rcParams['ytick.labelleft'] and rcParams['ytick.major.left'],  # new here
                labelright=rcParams['ytick.labelright'] and rcParams['ytick.major.right'], # new here
                which='major')
    

    This worked on my Linux machine running matplotlib 2.1.1. What do you think? If this does the job then I will also add the same for xtick.labeltop and xtick.labelbottom.

    The following code would produce the plots that show these changes worked. I also checked pandas basic plots, also worked for secondary_y parameter, although it'd swap the two y-axes around it doesn't seem to be a huge deal breaker.

    Any suggestion on any test cases? Not sure how that is usually done here.

    I have these changes ready for a PR, which branch should I submit this to?

    %matplotlib inline
    import matplotlib.pyplot as plt
    import matplotlib as mpl
    import numpy as np
    import pandas as pd
    
    print(mpl.rcParams['ytick.right'], mpl.rcParams['ytick.labelright'])
    print(mpl.rcParams['ytick.left'], mpl.rcParams['ytick.labelleft'])
    x = np.array([x for x in range(10)])
    plt.plot(x)
    
    y = np.array([y+10+np.random.normal(0, 3) for y in range(10)])
    df = pd.DataFrame([x,y]).T
    df.plot()
    
    df.plot(secondary_y=1)
    
  4. tgmiller5 commented on Feb 1, 2018

    @tgmiller5

    I am interested in participating in this. Is there a way to include me as a participant?

  5. QuLogic commented on Feb 7, 2018

    @QuLogic
    Member

    Fixed by #10306.

  6. added this to the milestone on Feb 7, 2018
  7. afvincent commented on Feb 7, 2018

    @afvincent
    Contributor

    @tgmiller5 Apologies for the answer delay!

    The issue was almost already fixed when you asked, but if you are still interested in participating into this kind of issues, you might want to have a look at similar issues tagged as good first issue, new-contributor-friendly and/or rcparams. For example, randomly picking one of them, one may try to revive #8479 (addressing #8109), which seems to have stalled.

  8. modified the milestones: , v2.2.0 on Feb 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesNew featuretopic: rcparams🌱 Good first issueOpen a pull request against these issues if there are no active ones!

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions