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
[Bug]: Autoscaling incorrect when scale set before adding collection #23129
Comments
Hmm, well, by default, add_collection() will trigger an "autolim"
calculation, which does deal with some minpos calculations like was pointed
out in the other issue. I am really curious about the order dependency, and
I wonder if addressing that would get this problem completely solved. As it
stands, if you set the yscale after adding the collection, then the data
limits would be computed using a linear scale instead of a log scale
otherwise.
…On Tue, May 24, 2022 at 8:52 PM Michael Waskom ***@***.***> wrote:
Bug summary
When using ax.add_collection and ax.set_{axis}scale, autoscaling works
properly only when they are called in that order, but not in the reverse
order.
Code for reproduction
import numpy as np, matplotlib as mpl, matplotlib.pyplot as pltax = plt.figure().subplots()xy = np.c_[np.arange(50), np.linspace(1, 100, 50)]lines = mpl.collections.LineCollection(segments=[xy])ax.set_yscale("log")ax.add_collection(lines)ax.autoscale_view()
Actual outcome
[image: image]
<https://user-images.githubusercontent.com/315810/170155179-44bfadac-1d30-48fe-ba6c-dceb9e1281c0.png>
Expected outcome
Swap the order of those calls:
import numpy as np, matplotlib as mpl, matplotlib.pyplot as pltax = plt.figure().subplots()xy = np.c_[np.arange(50), np.linspace(1, 100, 50)]lines = mpl.collections.LineCollection(segments=[xy])ax.add_collection(lines)ax.set_yscale("log")ax.autoscale_view()
[image: image]
<https://user-images.githubusercontent.com/315810/170155212-5bb8c389-97f3-4e1f-8810-08894bfa3809.png>
Additional information
This may be the same, or a related, issue as discussed here: #11898
<#11898>
@jklymak <https://github.com/jklymak>'s suggested workaround does appear
to work in my actual usecase, albeit with minimal testing. I don't feel
like I understand this corner of matplotlib quite well enough to say for
sure.
Operating system
*No response*
Matplotlib Version
3.5.2
Matplotlib Backend
*No response*
Python version
*No response*
Jupyter version
*No response*
Installation
*No response*
—
Reply to this email directly, view it on GitHub
<#23129>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACHF6ASGSSVPNHRUUW4LSDVLV2T7ANCNFSM5W3LQPCQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
It is still non-intuitive because other plotting methods don't have the same order-dependency. e.g. change the example to use |
Its definitely a transform problem which is hard to back out #11898 (comment) |
Hello everyone, After investigating this issue further, I've noticed that the datalim values in if not transform.is_affine:
paths = [transform.transform_path_non_affine(p) for p in paths] I'm curious about the specific purpose of this transformation and why the shape of the data matters for obtaining its bounding limits. While removing this transformation resolves the problem, I'd like to understand its original intent better. Despite its removal, the overall behavior remains consistent, and all tests pass seamlessly. |
…alim computations in Collections
…alim computations in Collections
Bug summary
When using
ax.add_collection
andax.set_{axis}scale
, autoscaling works properly only when they are called in that order, but not in the reverse order.Code for reproduction
Actual outcome
Expected outcome
Swap the order of those calls:
Additional information
This may be the same, or a related, issue as discussed here: #11898
@jklymak's suggested workaround does appear to work in my actual usecase, albeit with minimal testing. I don't feel like I understand this corner of matplotlib quite well enough to say for sure.
Matplotlib Version
3.5.2
The text was updated successfully, but these errors were encountered: