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

Addresses issue #23129: Fixed log scale order dependency when using Collections #28021

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Gerson-M-Ferreira
Copy link

This PR attempts to resolve issue #23129, in which there is an order dependency when using logaritmic scales and a Collection as data.

PR summary

Error Description

The error in axis computation originates from the add_collection() method within the _AxesBase class (found in lib/matplotlib/axes/_base.py). Specifically, the issue lies in how the axis limits are computed.

datalim = collection.get_datalim(self.transData)

Analysis

Further investigation into the get_datalim() method in the Collection class (lib/matplotlib/collections.py) reveals that data limits are influenced by a non-affine transformation:

    if not transform.is_affine:
        paths = [transform.transform_path_non_affine(p) for p in paths]

In scenarios where the axis scale is set after adding the data collection, and so the log scale is not yet applied, the data limits are computed as if the data were affine, and yet the correct behavior is achieved. In other words, the shape of the data should not impact bounding limit computation. Therefore, the non-affine transformation is not only unnecessary but also detrimental, as it produces inaccurate results, and its removal solves the issue.

Unit Test

Finnaly, a unit test was added, test_collection_log_datalim_order_dependency() (to lib/matplotlib/tests/test_collections.py), which validates the order dependency, ensuring the correctness of the fix.

PR checklist

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@Gerson-M-Ferreira
Copy link
Author

I'm leaving this comment since there has been no activity for a couple of weeks.

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

Successfully merging this pull request may close these issues.

[Bug]: Autoscaling incorrect when scale set before adding collection
1 participant