Skip to content

plt.stairs: fix unit handling for orientation="horizontal"#31666

Open
stiglers-eponym wants to merge 1 commit into
matplotlib:mainfrom
stiglers-eponym:fix_stairs_units
Open

plt.stairs: fix unit handling for orientation="horizontal"#31666
stiglers-eponym wants to merge 1 commit into
matplotlib:mainfrom
stiglers-eponym:fix_stairs_units

Conversation

@stiglers-eponym
Copy link
Copy Markdown

PR summary

plt.stairs or Axes.stairs calls self._process_unit_info as required for e.g. time dimensions on one axis. This PR introduces a distinction between vertical and horizontal orientation to fix the unit processing for orientation="horizontal".

Example

>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> times = np.arange(10).astype("M8[Y]")
>>> plt.stairs(np.random.random(9), times, orientation="horizontal")
<matplotlib.patches.StepPatch object at 0x7f5a834a3410>
>>> plt.show()
>>> # Old behavior: sets the x axis to time coordinates, but the y axis should contain time values.
>>> # New behavior: sets the y axis to time coordinates.

AI Disclosure

No AI was used for this PR.

PR checklist

Comment on lines +7833 to +7835
else:
edges, values, baseline = self._process_unit_info(
[("y", edges), ("x", values), ("x", baseline)], kwargs)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since vertical is the default, should it be the fallback position? Or will this error out if an orientation besides horizontal or vertical is provided?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just followed the convention that is used in mpatches.StepPatch (in patches.py) to which orientation is passed. The current behavior is that any value that is not "vertical" will be interpreted like "horizontal".

One can of course change this behavior, but that was not my intention in this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hear that that's a separate discussion. I'm also wondering why stairs has to do unit processing if it's being done inside the patch creation code. Is it cause of:

https://github.com/stiglers-eponym/matplotlib/blob/6bcc38ad70066c391e327884af8bf917975cfd3f/lib/matplotlib/axes/_axes.py#L7855-L7863

And if so can that information be populated from patch.get_data()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants