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

Add function set_min_axis_range() #26

Merged
merged 2 commits into from
Sep 26, 2022
Merged

Add function set_min_axis_range() #26

merged 2 commits into from
Sep 26, 2022

Conversation

taldcroft
Copy link
Member

@taldcroft taldcroft commented Sep 21, 2022

Description

Add a function to set the minimum range of the y- or x-axis limits of a matplotlib Axes object. This is used to prevent the axis limits from being set to a very small range.

Interface impacts

None

Testing

Unit tests

  • No unit tests

Functional tests

>>> %matplotlib
Using matplotlib backend: MacOSX
>>> from Ska.Matplotlib import set_min_axis_range
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots()
>>> ax.plot([0, 1, 2], [0.0, 0.01, -0.02])
>>> set_min_axis_range(ax, 1.0)
>>> set_min_axis_range(ax, 5.0, axis='x')

image

>>> fig, ax = plt.subplots()
>>> ax.plot([0, 1, 2], [0.0, 0.01, -0.02])
[<matplotlib.lines.Line2D object at 0x7fc8407ebbe0>]
>>> ax.set_ylim(0.1, -0.1)
(0.1, -0.1)
>>> set_min_axis_range(ax, 1.0)

image

@jeanconn
Copy link
Contributor

To be completely general, I would think the "+" and "-" at the end would need to be handled for the case of flipped axis?

@taldcroft
Copy link
Member Author

Great catch @jeanconn, fixed. I put a new functional test in the description.

Copy link
Contributor

@jeanconn jeanconn left a comment

Choose a reason for hiding this comment

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

Probably not perfect for log plots but fine for most use cases.

@javierggt javierggt mentioned this pull request Sep 26, 2022
51 tasks
@taldcroft taldcroft merged commit e884472 into master Sep 26, 2022
@taldcroft taldcroft deleted the set-min-ylim branch September 26, 2022 20:19
This was referenced Oct 5, 2022
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