-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Adding twin axes to an axis with GridHelperCurveLinear (from example) makes some ticklabels disappear #10748
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
Comments
@ImportanceOfBeingErnest Regarding your comment I'm trying to fix some things in I have found the source of this issue here, at least why the tickmarks etc are gone. The twin()-method makes the "top" and "right" axes invisible. This is actually the same behaviour as in twinx(). What needs decision is the wanted default behaviour. Should all possible axes be displayed by default? Sure the added image is not how we want to have it (all possible axes visible). @Sup3rGeo Any ideas how this should look like? So, questions are, where to put the different axes and which should be made invisible. This decision also affects the remove method. |
@smheidrich Sorry for disturbing, I'm trying to understand which axes need to be visible and which not. And for sure, the most logical solution. Looking at the commented code fragments before your changes in d268abf there has been quite some testing to probably find a nice solution. Do you remember why you've prefered this solution? |
@kmuehlbauer The point behind my changes is summarized in the difference between the two images in this comment (which was also put into the tests as By the way, there was another issue stemming from my changes that never got fixed, summarized here - but I guess that is a slightly different issue and this here relates to just |
I have to say I don't know what the expected outcome of the code here should be. I think the images in the comment in #4898 by @smheidrich are pretty convincing. So in this case I would think that due to the use of the |
@smheidrich Thanks for coming back to this, and for the pointers. I'll have another look into this the next days adding some of my use cases here. @ImportanceOfBeingErnest I adapted my use case from a matplotlib example. I'm not sure, if I used the API correctly but we will find out. Thanks for responding, all. |
It would still be consistent if Are the plots which are generated for the gallery and docs part of CI by now, with image comparison tests? That would come in handy when changing anything in |
The documentation is tested in the sense that it generates successfully. If an example from the gallery was to error out, the test would fail. However there is no image comparisson. If an example simply produces some wrong image this is not caught. Of course one could simply copy the code from any example and create a test from it. In general, the number of image comparissons should not grow too large, and sometimes it would be enough to test for certain things like visibility or positions. Possibly, several examples can also be combined into a single image comparisson. |
I see, thanks! |
This is a stripped down version of my use case: import matplotlib.pyplot as pl
import numpy as np
from matplotlib.projections import PolarAxes
from matplotlib.transforms import Affine2D
from mpl_toolkits.axisartist import (SubplotHost, GridHelperCurveLinear)
from mpl_toolkits.axisartist.grid_finder import FixedLocator, DictFormatter
import mpl_toolkits.axisartist.angle_helper as ah
# Transformation for polar data
# Set theta start to north
tr_rotate = Affine2D().translate(-90, 0)
# set theta running clockwise
tr_scale = Affine2D().scale(-np.pi / 180, 1)
# create transformation
tr = tr_rotate + tr_scale + PolarAxes.PolarTransform()
# build up curvelinear grid
extreme_finder = ah.ExtremeFinderCycle(20, 20,
lon_cycle=360,
lat_cycle=None,
lon_minmax=(360, 0),
lat_minmax=(0, np.inf),
)
# locator and formatter for angle annotation
locs = [i for i in np.arange(0., 359., 10.)]
grid_locator1 = FixedLocator(locs)
tick_formatter1 = DictFormatter(dict([(i, r"${0:.0f}^\circ$".format(i))
for i in locs]))
# grid_helper for curvelinear grid
grid_helper = GridHelperCurveLinear(tr,
extreme_finder=extreme_finder,
grid_locator1=grid_locator1,
grid_locator2=None,
tick_formatter1=tick_formatter1,
tick_formatter2=None,
)
# try to set nice locations for range gridlines
grid_helper.grid_finder.grid_locator2._nbins = 15.0
grid_helper.grid_finder.grid_locator2._steps = [0, 1, 1.5, 2,
2.5,
5,
10]
fig = pl.figure(figsize=(6,5))
# generate curvelinear grid axis
cgax = SubplotHost(fig, 111, grid_helper=grid_helper)
fig.add_axes(cgax)
cgax.set_aspect('equal', adjustable='box')
# get twin axis for cartesian grid
caax = cgax.twin()
# make everything look right
# cgax.axis["top", "right"].set_visible(True)
# cgax.axis["top", "right"].major_ticklabels.set_visible(True)
# cgax.axis["left", "bottom"].major_ticks.set_visible(False)
# cgax.axis["left", "bottom"].major_ticklabels.set_visible(False)
# caax.axis["left", "bottom"].set_visible(True)
# caax.axis["left", "bottom"].major_ticklabels.set_visible(True)
# caax.axis["top", "right"].set_visible(False)
# show curvelinear and cartesian grids
cgax.grid(True)
caax.grid(True)
t = pl.title('Simple Curvelinear Grid')
t.set_y(1.05)
pl.show() Retested with d5a4eda, updated code |
Status Quo, created with d5a4eda |
Wanted, created with d5a4eda |
Just remove the comments below the line containing |
The current behaviour makes This is all true for the current configuration (xlim/ylim: 0,1). But think of (xlim/ylim: -1,0), Then the different axes need to be on the opposite of each other (at least the axes with the angles, see image below, created with d5a4eda) . So, currently I'm a bit at loss, if there is single fitting solution at all. |
Should it be that easy now? OK, in self.axis["top", "right"].set_visible(False)
ax2.axis["top", "right"].set_visible(True)
ax2.axis["left", "bottom"].set_visible(False) So the # make everything look right
caax.axis["top", "right"].toggle(all=True) then I get an image with all wanted axes (see below, created with d5a4eda). We see that the placement of the |
In the light of these examples, it seems that the only problem with the current code is, that the ticks etc are not visible. My question is: Is this intended behaviour? |
@smheidrich @ImportanceOfBeingErnest Can someone please sanity check? The problem of the original poster @Sup3rGeo is that his angular (?) axis spans over three axes ( To solve this just one line has to be added restoring the original ax.axis["top"].set_visible(True) |
I am actually quite beginner with matplotlib and it has been a while since I opened this one, so I am not totally sharp. But I think I agree with @ImportanceOfBeingErnest:
In general I would not expect anything on the host axis to be hidden when adding a twin, it was a bit confusing. Then when adjusting the axis, if there is no one-size-fits-all, the possibilities should be at least well documented. |
@Sup3rGeo Thanks for responding. I would also agree, that it's a bit confusing if parts of the original host axis are silently hidden. I searched the current examples/demos but couldn't find anything related to this specific behaviour. Why not add nice example showing how to handle this specific use case? Also the twin()-function docstring needs an update, it is the same as twinx() currently. Other opinions? |
Just so I understand: Does the issue of "angle" ticklabels being drawn on top of each other in the bottom left corner of #10748 (comment) have anything to do with this If it is a separate issue, the only issue here is that nothing on the host axes should be hidden when using any of the As I wrote in #10748 (comment), this basically means changing I also agree that the |
@smheidrich Correct, this particular problem has nothing to do with this issue, hence I wrote "But we can't do much about it."
This sounds reasonable to me. It does not hide anything on the host axes and simplifies code.
For sure! 😁 |
All right then, should I submit a PR or is anyone else already working on it? Or is there something else to discuss first? |
PR matplotlib#4896 changed the behavior of twinx() and twiny() in axes_grid1 to make them consistent with twin(). This commit inverts the "direction" of consistency and makes twin() behave like the pre-matplotlib#4896 twinx() and twiny() instead. This way, the API becomes less surprising: instead of hiding certain host axes, twin* now keeps the host axes unmodified, while the parasite axes have their axis lines hidden instead. Unfortunately, this change breaks backwards-compatibility for code relying on the specifics of host and parasite axes visibility. Helps with matplotlib#10748.
PR matplotlib#4896 changed the behavior of twinx() and twiny() in axes_grid1 to make them consistent with twin(). This commit inverts the "direction" of consistency and makes twin() behave like the pre-matplotlib#4896 twinx() and twiny() instead. This way, the API becomes less surprising: instead of hiding certain host axes, twin* now keeps the host axes unmodified, while the parasite axes have their axis lines hidden instead. Unfortunately, this change breaks backwards-compatibility for code relying on the specifics of host and parasite axes visibility. Helps with matplotlib#10748.
PR matplotlib#4898 changed the behavior of twinx() and twiny() in axes_grid1 to make them consistent with twin(). This commit inverts the "direction" of consistency and makes twin() behave like the pre-matplotlib#4898 twinx() and twiny() instead. This way, the API becomes less surprising: instead of hiding certain host axes, twin* now keeps the host axes unmodified, while the parasite axes have their axis lines hidden instead. Unfortunately, this change breaks backwards-compatibility for code relying on the specifics of host and parasite axes visibility. Helps with matplotlib#10748.
PR matplotlib#4898 changed the behavior of twinx() and twiny() in axes_grid1 to make them consistent with twin(). This commit inverts the "direction" of consistency and makes twin() behave like the pre-matplotlib#4898 twinx() and twiny() instead. This way, the API becomes less surprising: instead of hiding certain host axes, twin* now keeps the host axes unmodified, while the parasite axes have their axis lines hidden instead. Unfortunately, this change breaks backwards-compatibility for code relying on the specifics of host and parasite axes visibility. Helps with matplotlib#10748.
PR matplotlib#4898 changed the behavior of twinx() and twiny() in axes_grid1 to make them consistent with twin(). This commit inverts the "direction" of consistency and makes twin() behave like the pre-matplotlib#4898 twinx() and twiny() instead. This way, the API becomes less surprising: instead of hiding certain host axes, twin* now keeps the host axes unmodified, while the parasite axes have their axis lines hidden instead. Unfortunately, this change breaks backwards-compatibility for code relying on the specifics of host and parasite axes visibility. Helps with matplotlib#10748.
PR matplotlib#4898 changed the behavior of twinx() and twiny() in axes_grid1 to make them consistent with twin(). This commit inverts the "direction" of consistency and makes twin() behave like the pre-matplotlib#4898 twinx() and twiny() instead. This way, the API becomes less surprising: instead of hiding certain host axes, twin* now keeps the host axes unmodified, while the parasite axes have their axis lines hidden instead. Unfortunately, this change breaks backwards-compatibility for code relying on the specifics of host and parasite axes visibility. Helps with matplotlib#10748.
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! |
Bug report
Bug summary
Adding twin axes to another axis created with gridhelper GridHelperCurveLinear makes some of the ticklabels of the polar grid disappear.
Code for reproduction
Working fine:
Results in:

Adding this however:
Results in lost ticklabels for the upper part:
Matplotlib version
print(matplotlib.get_backend())
): TkAggInstalled from pip.
The text was updated successfully, but these errors were encountered: