Skip to content

Feature Request: Controlling top, bottom, left, and right tick parameters independently of one another #11837

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

Closed
ghost opened this issue Aug 9, 2018 · 4 comments
Labels
New feature status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. status: inactive Marked by the “Stale” Github Action

Comments

@ghost
Copy link

ghost commented Aug 9, 2018

matplotlib.axes.Axes.tick_params allows one to control the direction which the ticks along the x and y axes point. Currently this can either be set to in or out which is very useful, but sometimes I want to create a plot that has ticks along the bottom pointing out and ticks along the top pointing in and I was unable to find an easy solution to accomplish this as tick_params for top and bottom are both tied to the x-axis. I am currently able to accomplish what I want by using and ax.twiny():

fig, ax = plt.subplots()

majorLocator = AutoLocator()
minorLocator = AutoMinorLocator()

ax_top = ax.twiny()
ax_top.tick_params(which='both', direction='in')
ax_top.set_xlim(ax.get_xlim())

ax.xaxis.set_minor_locator(minorLocator)
ax.xaxis.set_major_locator(majorLocator)

ax_top.xaxis.set_minor_locator(minorLocator)
ax_top.xaxis.set_major_locator(majorLocator)

ax_top.get_shared_x_axes().join(ax_top, ax)
ax_top.set_xticklabels([])

unknown
but this seems like a messy solution

@afvincent
Copy link
Contributor

I agree that a more concise and user-friendly way to achieve this would be a nice feature to have from a user perspective. In some fields (at least the few ones that I know), these kinds of tick directions are rather common. For the record, a “recent” Gitter discussion related to the same topic occurred here.

@ImportanceOfBeingErnest
Copy link
Member

If I see it correctly this should be simplified by the secondary_xaxis proposed in #11589, it should then look like (the API there is not yet finalized, so this is a rough estimate):

fig, ax = plt.subplots()
ax.minorticks_on()

ax_top = ax.secondary_xaxis('top', 1)
ax_top.minorticks_on()
ax_top.tick_params(which='x', direction='in', labeltop=False)

Even simpler solution would require something like proposed here.

@jklymak
Copy link
Member

jklymak commented Aug 15, 2018

As #11859 (note new PR number) stands now, this is:

import numpy as np
import matplotlib.pyplot as plt

convert = 1

fig, ax = plt.subplots()

ax.minorticks_on()

axsecond = ax.secondary_xaxis('top', conversion=convert)
axsecond.minorticks_on()
axsecond.tick_params(axis='x', which='both', direction='in', labeltop=False)

figure_4

However if the xaxis has customized Locators and Formatters, these will not (currently) be shared with the secondary axes. Worse, I don't quite have a good API for setting the secondary axes Locators and Formatters, because they get reset every draw time to be consistent with the parent's scale (log or linear). This is a pretty big issue with #11859 at the momment, but hopefully we can work something out.

@github-actions
Copy link

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label May 12, 2023
@github-actions github-actions bot added the status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. label Jun 12, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New feature status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. status: inactive Marked by the “Stale” Github Action
Projects
None yet
Development

No branches or pull requests

3 participants