Skip to content

fixing 3d ticks direction #22517

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
wants to merge 23 commits into from
Closed

fixing 3d ticks direction #22517

wants to merge 23 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Feb 21, 2022

fixing 3d tick:
#21729

seems to be working:
ax.set_xlabel(r"$x$")
ax.set_ylabel(r"$y$")
ax.set_zlabel(r"$z$")
ax.tick_params(axis='x', which='major', direction='inout')
ax.tick_params(axis='y', which='major', direction='in')
ax.tick_params(axis='z', which='major', direction='out')
Figure_1

@ghost
Copy link
Author

ghost commented Feb 21, 2022

it seems some image comparisons tests fail. this is most likely because before it was 'inout' displayed even though default is 'out'? That would be my guess.

@ghost
Copy link
Author

ghost commented Feb 24, 2022

I looked at the failing tests - and it seems all of them are the "out" default, which was before "inout" as it was done incorrectly. So the fix seems to be correct.

wireframe3dzerorstride
wireframe3dzerorstride-expected

@oscargus oscargus added status: needs workflow approval For PRs from new contributors, from which GitHub blocks workflows by default. topic: ticks axis labels labels Feb 24, 2022
@timhoffm
Copy link
Member

Thanks, making this configurable is good. I think the previous state was just hard-coded to an 'in-out' solution and ignoring the tick params settings.

There's a bit of trouble with the defaults: On 2D we have classes XTick and YTick, which take their defaults from rcParams['xtick.direction'] and rcParams['ytick.direction'].
On 3D all directions populate their axis with XTick and take their value from rcParams['xtick.direction']. Note that we neither have a ZTick class nor rcParams['ztick.*'].
Also note that this inconsistency has existed for other tick defaults rcParams['xticks.*'] (e.g. xticks.color) as well. So this is not new, it just becomes additionally visible in the tick direction now that it is not hard-coded anymore but follows rcParams['xticks.direction'].

There are several ways one could go forward, however I think the following is the best for now:
Patch the 3D ticks to default to a hard-coded internal 'inout', but let it be overwritten by tick_params(direction=...).

Advantages:

  • We do not modify existing plots/defaults
  • Users can now change the direction via tick_params(direction=...).
  • We don't have to get into the business of untangling the rcParams mess for 3d ticks right now.
  • This is still open for future changes. Any additional change we could make here now can be added later with the same amount of user impact.

Disadvantages:

  • The tick direction is still not configurable via rcParams.

I have not looked into the details how the 3D tick default direction could be patched, but assume that it can be done by a few lines of code.
This is a bit hacky, but every other solution will require either significant rewrites for 3D tick handling, or changed default behavior or have inconsistencies in rcParams usage; likely two or all three of them.

@ghost
Copy link
Author

ghost commented Feb 25, 2022

@timhoffm, so you want me to add code, which will be removed anyway just to postpone fixing the tests? I can't say I see any advantages in that, just disadvantages.

@timhoffm
Copy link
Member

The suggestions is not motivated by the tests. This is about user-facing behavior and API.

Before the tick direction was hard-coded. If we now do nothing special, the default tick direction would be determined by rcParams['xticks.direction'] for all axes.

  1. This would change the default behavior from 'out' to 'inout'. We are very hesitant with such changes because it changes the appearance of user figures. Even if that's acceptable, we have an additional complication:
  2. The ticks directions for all 3D axes are taken from 'xticks.direction' (because for some reason they are all XTick instances). In contrast, for 2D we use 'xticks.direction' and 'yticks.direction'.
    There are again two possible ways out:
    3a) Create a new 3dticks.direction rcParam (naming t.b.d.) - Possibly, what's a good default for 2D is not necessarily a good default for 3D.
    3b) Change the 3D ticks to XTicks, YTicks and create a new ZTicks class and add 'zticks.*' rcParams.
    Both 3a) and 3b) would require quite a bit internal refactoring.

In summary, as soon as we start using rcParams for 3D, we are getting undesired API/behavior in the intermediate solutions. Only if we fully implement 3a or 3b, we get back to a reasonable API. But that's requires quite a bit internal restructuring, and we would need to decide whether 3a or 3b is the desired solution. IHMO this is beyond the scope of this PR and could significantly delay the adoption of this PR.

@ghost
Copy link
Author

ghost commented Feb 26, 2022

Thank you for explanations Tim. Yes, indeed it seems there is much more work on this. I just wanted to add ability to do the ticks 'in' as sometimes they went out and got too close to text and it made it look a bit weird - not acceptable for publication. By adding ability setting ticks 'in', it would resolve a lot of headaches in the future.

@oscargus
Copy link
Member

oscargus commented Mar 2, 2022

I may be late on the ball here and not following all the discussions properly, but wouldn't it make sense to not change the test images, but to use the same styles for them? And then add one image, like the one in the opening post of this PR to prove the functionality?

This is from the aspect of saving repository space by not updating test images unless absolutely necessary.

(Being able to configure it is 👍🏻 )

@ghost
Copy link
Author

ghost commented Mar 2, 2022

Well, quite frankly I am bit lost here.

I may be late on the ball here and not following all the discussions properly, but wouldn't it make sense to not change the test images, but to use the same styles for them? And then add one image, like the one in the opening post of this PR to prove the functionality?

This is from the aspect of saving repository space by not updating test images unless absolutely necessary.

(Being able to configure it is 👍🏻 )

@ghost ghost closed this Mar 2, 2022
@ghost ghost deleted the tick3dfix branch March 2, 2022 15:58
@timhoffm
Copy link
Member

timhoffm commented Mar 3, 2022

@oscargus: Yes.

@Pepe78: Have we scared you away? If so, sorry for that. The large user base and legacy code makes it sometimes hard to introduce changes or even only fixes. But your PR is a good addition and there's not much lacking for it to be merged.

@ghost
Copy link
Author

ghost commented Mar 3, 2022

Hah. No. I just realized that it takes shorter time to write my own libraries than checking in three and half lines of code fix into matplotlib:
https://github.com/pepe78/subdivision_opencl
(to be specific: https://github.com/pepe78/subdivision_opencl/blob/main/display.py)

as i am currently considering switching languages anyway:
https://github.com/pepe78/python-performance

I guess i will be most likely using other library in future for displaying graphs anyway (maybe rust?).

@ghost
Copy link
Author

ghost commented Mar 3, 2022

Sorry that I wasn't more helpful. You guys can take the code and check it in if you know how to do it properly. I obviously didn't.

@WeatherGod
Copy link
Member

WeatherGod commented Mar 3, 2022 via email

@ghost
Copy link
Author

ghost commented Mar 3, 2022

Thanks :) - as I said - I wished I was more helpful. I understand that matplotlib is going through a lot of changes (I actually looked at a lot of code) and I saw you guys are trying to figure the best ways (which is often hard on a moving train). I just felt I am going to slow you down :). And yes, matplotlib can be used with other languages as well. Happy plotting (I will still be using matplotlib a lot in future).

@timhoffm timhoffm self-assigned this Mar 3, 2022
@timhoffm
Copy link
Member

timhoffm commented Mar 3, 2022

Will try to pick this up after #22587 is in.

@ghost
Copy link
Author

ghost commented Mar 26, 2022

Just FYI - matplotlib's 3D graphs got into my latest publications:
https://www.sciencedirect.com/science/article/pii/S0167691122000329

So Thank you for all the hard work to make them look pretty!

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs workflow approval For PRs from new contributors, from which GitHub blocks workflows by default. topic: ticks axis labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants