Skip to content
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

Plotting into an existing axes replaces axes limits #407

Open
jl-wynen opened this issue Jan 31, 2025 · 3 comments
Open

Plotting into an existing axes replaces axes limits #407

jl-wynen opened this issue Jan 31, 2025 · 3 comments

Comments

@jl-wynen
Copy link
Member

When plotting multiple data arrays into the same MPL Axes, the axes limits are replaced. E.g.,

import scipp as sc
import matplotlib.pyplot as plt
a = sc.DataArray(sc.ones(sizes={'x': 3}), coords={'x': sc.arange('x', 3)})
b = 10 * a

fig, ax = plt.subplots()
a.plot(ax=ax)
b.plot(ax=ax)

produces
Image
that is, the points of a are not visible.

I would expect this to behave more like MPL where we can use ax.plot multiple times and get limits that encompass all data.

@nvaytet
Copy link
Member

nvaytet commented Jan 31, 2025

This is probably because it's difficult to keep everyone happy.

It comes from the fact that when doing b.plot(ax=ax), the figure created there is unaware of what was done to ax before.
In your case, you can either

fig, ax = plt.subplots()
a.plot(ax=ax)
b.plot(ax=ax)
ax.autoscale()

or use

import plopp as pp
pp.plot({'a': a, 'b': b})

@nvaytet
Copy link
Member

nvaytet commented Feb 6, 2025

@jl-wynen do you still want to modify the behaviour or are the suggested fixes above enough?

@jl-wynen
Copy link
Member Author

jl-wynen commented Feb 6, 2025

In principle they are enough. I just find it surprising that it behaves differently from plain matplotlib.

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

No branches or pull requests

2 participants