Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
esvhd opened this issue Jan 19, 2018 · 6 comments
Closed
Labels
Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Good first issue Open a pull request against these issues if there are no active ones! New feature topic: rcparams
Milestone

Comments

@esvhd
Copy link
Contributor

esvhd commented Jan 19, 2018

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.

@jklymak jklymak added new-contributor-friendly Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues topic: rcparams Good first issue Open a pull request against these issues if there are no active ones! New feature labels Jan 20, 2018
@jklymak
Copy link
Member

jklymak commented Jan 20, 2018

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

@esvhd
Copy link
Contributor Author

esvhd commented Jan 21, 2018 via email

@esvhd
Copy link
Contributor Author

esvhd commented Jan 21, 2018

@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)

@tgmiller5
Copy link

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

@QuLogic
Copy link
Member

QuLogic commented Feb 7, 2018

Fixed by #10306.

@QuLogic QuLogic closed this as completed Feb 7, 2018
@QuLogic QuLogic added this to the v2.2 milestone Feb 7, 2018
@afvincent
Copy link
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.

@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0 Feb 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Good first issue Open a pull request against these issues if there are no active ones! New feature topic: rcparams
Projects
None yet
Development

No branches or pull requests

5 participants