-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add ytick label right/left properties in matplotlibrc #10306
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
Conversation
lib/matplotlib/axes/_base.py
Outdated
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'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should indent a 8 spaces or so here...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep sounds good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually when I indented like the below I got some PEP 8 complains. Was this what you meant?
Alternatively I can have this in a single line but it breaches 80 line margin.
labelleft=rcParams['ytick.labelleft'] and
rcParams['ytick.major.left'],
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put the RHS in parentheses and then it should work with indenting...
This at least needs a test. w/o looking at the rest of the code, I don't quite understand how this propagates to the axis drawing. |
Essentially I traced down how All up for testing, any suggestion on how this should be tested? Any example tests you can point me to perhaps? |
Tests are in |
Good idea.
…Sent from my iPhone
On 26 Jan 2018, at 21:45, Jody Klymak ***@***.***> wrote:
@jklymak commented on this pull request.
In lib/matplotlib/axes/_base.py:
> 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'],
Put the RHS in parentheses and then it should work with indenting...
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Added a test case I tested the test case manually in a notebook and all asserts worked. However, when I tried to run
When I ran Thx |
Are you sure you are using the same environment in each case? |
Sorry not an expert in this clearly. Could you please clarify what you mean
by same environment? Thx
…On Sun, Jan 28, 2018 at 9:37 PM, Jody Klymak ***@***.***> wrote:
Are you sure you are using the same environment in each case?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#10306 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AG_aUd41pYaazH1w3EPMjqA_e85qXnkBks5tPOikgaJpZM4RqZFS>
.
|
If you are using conda environments, then |
I see, conda environments. Yes, the env that has this code change has
`fontconfig`. I was being lazy so I hacked my installed `matplotlib` code
with these changes and tested in my notebooks manually (including running
the test code)..
…On Sun, Jan 28, 2018 at 10:14 PM, Jody Klymak ***@***.***> wrote:
If you are using conda environments, then fontconfig has to be installed
in your test environment. If you aren't using environments you should 😉
https://conda.io/docs/user-guide/tasks/manage-environments.html
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#10306 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AG_aUVD2OkcAdYySv-cz7q68HDvYQoPVks5tPPFCgaJpZM4RqZFS>
.
|
OK, this is almost done. This could use a "whats-new" entry: see Ideally, you would also have an example for it, particulaly one that differentiates it from Thanks for all your work on this! |
Sounds good, let me look into these. Thx for the pointers.
…On Mon, Jan 29, 2018 at 5:02 PM, Jody Klymak ***@***.***> wrote:
OK, this is almost done. This could use a "whats-new" entry: see
doc/users/next_whats_new
Ideally, you would also have an example for it, particulaly one that
differentiates it from ax.yaxis.tick_right()... examples/ticks_and_spines
I expect. I note that we don't have any examples with tick_right(), so if
you could include that too, it'd be fabulous.
Thanks for all your work on this!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#10306 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AG_aUYSj1vWQeXWzvK1Al8IrIp8iASfJks5tPfm-gaJpZM4RqZFS>
.
|
Added example to show how to set these new properties in |
Hmmm. Is this how the example is supposed to look? I'd have expected the ticks and labels to be on the right for the last subplot ( |
I think that the rcParams might be read at the figure instantiation, i.e. changing them afterwards like in the example will have no effect. (But I may be wrong.) |
Not |
Fixed the example. Needed to set |
============================================ | ||
|
||
Example to show how to change two new properties in rcParams to put yaxis tick | ||
lables on either left or right by default. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the text should not refer to "new" properties (unless you plan to edit this in a year). Also some formatting changes. (Note I didn't check the comment below for length).
Otherwise looks great!
"""
We can use :rc:`ytick.labelright` (default False) and :rc:`ytick.right` (default False)
and :rc:`ytick.labelleft` (default True) and :rc:`ytick.left` (default False) to
control where on the axes ticks and their labels appear. These properties can also be
set in the ``.matplotlib/matplotlibrc``.
"""
Sure, will add these changes later today.
…Sent from my iPhone
On 30 Jan 2018, at 23:37, Jody Klymak ***@***.***> wrote:
@jklymak requested changes on this pull request.
In examples/ticks_and_spines/tick_label_right.py:
> @@ -0,0 +1,33 @@
+"""
+============================================
+Set default y-axis tick labels on the right
+============================================
+
+Example to show how to change two new properties in rcParams to put yaxis tick
+lables on either left or right by default.
I think the text should not refer to "new" properties (unless you plan to edit this in a year). Also some formatting changes. (Note I didn't check the comment below for length).
Otherwise looks great!
"""
We can use :rc:`ytick.labelright` (default False) and :rc:`ytick.right` (default False)
and :rc:`ytick.labelleft` (default True) and :rc:`ytick.left` (default False) to
control where on the axes ticks and their labels appear. These properties can also be
set in the ``.matplotlib/matplotlibrc``.
"""
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Hope this looks good. Thanks guys! |
About the issue with having the x-ticks and x-tick labels at the top that do not play well with a possible title, I do not think that adding new rcParams is very different from the current situation when the x-ticks and their label are tuned through the proper I guess that a quick workaround if some core devs are afraid of this issue might be to simply advertise that one can increase the title padding. A genuine first thought that comes to me is something like. import matplotlib.pyplot as plt
# If a fixed title padding is good enough
#plt.rcParams["axes.titlepad"] = 36 # 24 without x-label
fig, axs = plt.subplots(ncols=2)
for ax, xlbl in zip(axs.flat, ("X-label", "")):
ax.plot([0, 1])
ax.set_title("A title")
ax.set_xlabel(xlbl)
ax.xaxis.tick_top()
ax.xaxis.set_label_position('top')
# Dynamic title padding if one prefers
for ax in axs.flat:
ax.set_title(ax.get_title(), pad=36 if len(ax.get_xlabel()) > 0 else 24)
fig.tight_layout()
plt.show() |
Or, you know, #9498 which will do this automatically. |
Here we go. Added Currently this quick solution does not take care of title position. I understood that this is being worked on separately as @jklymak suggested. Let me know how this looks. Thanks everyone. |
I have a concern about the git history; someone with more git knowledge can comment on whether something should be done about it, and if so, what. Normally we do not merge master into feature branches. Instead, to keep them up to date, we rebase them on top of the master branch. |
Would be great if someone can shed some light on this, not a git pro here. Thx |
I think these are just merge commits and are OK. OTOH these commits would be better if they were rebased into one commit. Oddly, given how much we ask people to squash things: https://matplotlib.org/devdocs/devel/gitwash/development_workflow.html doesn't describe the process, but this is what I do: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-approve the new changes.
plt.rcParams['ytick.left'], plt.rcParams['ytick.labelleft'] = False, False | ||
|
||
|
||
x = np.array([x for x in range(10)]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np.arange(10)
plt.rcParams['xtick.bottom'], plt.rcParams['xtick.labelbottom'] = False, False | ||
plt.rcParams['xtick.top'], plt.rcParams['xtick.labeltop'] = True, True | ||
|
||
x = np.array([x for x in range(10)]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np.arange(10)
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
plt.rcParams['ytick.right'], plt.rcParams['ytick.labelright'] = True, True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chained assignment would be a bit simpler:
plt.rcParams['ytick.right'] = plt.rcParams['ytick.labelright'] = True
lib/matplotlib/tests/test_axes.py
Outdated
ax.tick_params(labelleft=False, labelright=True, | ||
which='minor') | ||
# expects left false, right true | ||
assert(ax.yaxis.majorTicks[0].label1On is False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary parentheses.
|
||
|
||
x = np.array([x for x in range(10)]) | ||
x = np.array([x for x in np.range(10)]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I mean you can replace the entire line with np.arange(10)
.
Added suggested changes from @QuLogic |
good idea. let me do that.
…On Sun, Feb 4, 2018 at 9:03 PM, Elliott Sales de Andrade < ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In examples/ticks_and_spines/tick_label_right.py
<#10306 (comment)>
:
>
-x = np.array([x for x in range(10)])
+x = np.array([x for x in np.range(10)])
No, I mean you can replace the entire line with np.arange(10).
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#10306 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AG_aUTt6HtkuzMQ3tI1xkBVs1nB3M4l4ks5tRhsxgaJpZM4RqZFS>
.
|
Hi guys, checking in on this, is there any more work need on this PR, particularly from my side? |
Excellent. Thanks so much @esvhd! Great contribution.... |
OOification of the new examples from #10306
PR Summary
Add y-axis tick label positions into
matplotlibrc
for issue #10267New properties named as:
ytick.labelleft
ytick.labelright
Will also work on a PR for x-axis tick label top/bottom properties for
matplotlibrc