{{ message }}
Check for float values for min/max values to ax{v,h}line - #17822
Merged
Merged
Conversation
Member
Member
Author
|
I found |
Member
|
On master import matplotlib.pyplot as plt
import matplotlib.dates as mdates
line = plt.axvline(
x=.5, ymin=mdates.num2date(1), ymax=mdates.num2date(1.05))
line.set_clip_on(False)
plt.show()already errors out: So is the point of this PR to just make the error more explicit? If so, I don't think it needs an API change or note, because I guess that has already occurred. |
Member
|
That specific example broke in a793bde, which is a date-specific change. Is it still true that other unit-ful values are currently broken? |
Member
Author
|
Yes, I think it might just be a better error now, with the following example import matplotlib.pyplot as plt
import astropy.units as u
from astropy.visualization import quantity_support
quantity_support()
fig, ax = plt.subplots()
ax.scatter(1 * u.m, 1 * u.s)
ax.axhline(1 * u.s, xmin=0.1 * u.m)
plt.show()The error before was Traceback (most recent call last):
File "/Users/dstansby/github/matplotlib/lib/matplotlib/axis.py", line 1524, in convert_units
ret = self.converter.convert(x, self.units, self)
File "/Users/dstansby/github/astropy/astropy/visualization/units.py", line 102, in convert
return [v.to_value(unit) for v in val]
File "/Users/dstansby/github/astropy/astropy/visualization/units.py", line 102, in <listcomp>
return [v.to_value(unit) for v in val]
AttributeError: 'int' object has no attribute 'to_value'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "test.py", line 8, in <module>
ax.axhline(1 * u.s, xmin=0.1 * u.m)
File "/Users/dstansby/github/matplotlib/lib/matplotlib/axes/_axes.py", line 847, in axhline
self.add_line(l)
File "/Users/dstansby/github/matplotlib/lib/matplotlib/axes/_base.py", line 1977, in add_line
self._update_line_limits(line)
File "/Users/dstansby/github/matplotlib/lib/matplotlib/axes/_base.py", line 1999, in _update_line_limits
path = line.get_path()
File "/Users/dstansby/github/matplotlib/lib/matplotlib/lines.py", line 1011, in get_path
self.recache()
File "/Users/dstansby/github/matplotlib/lib/matplotlib/lines.py", line 652, in recache
xconv = self.convert_xunits(self._xorig)
File "/Users/dstansby/github/matplotlib/lib/matplotlib/artist.py", line 175, in convert_xunits
return ax.xaxis.convert_units(x)
File "/Users/dstansby/github/matplotlib/lib/matplotlib/axis.py", line 1526, in convert_units
raise munits.ConversionError('Failed to convert value(s) to axis '
matplotlib.units.ConversionError: Failed to convert value(s) to axis units: [<Quantity 0.1 m>, 1]And the error with this PR is Traceback (most recent call last):
File "test.py", line 8, in <module>
ax.axhline(1 * u.s, xmin=0.1 * u.m)
File "/Users/dstansby/github/matplotlib/lib/matplotlib/axes/_axes.py", line 834, in axhline
self._check_no_units([xmin, xmax], ['xmin', 'xmax'])
File "/Users/dstansby/github/matplotlib/lib/matplotlib/axes/_axes.py", line 926, in _check_no_units
raise ValueError(f"{name} must be a single scalar value, "
ValueError: xmin must be a single scalar value, but got 0.1 m |
jklymak
approved these changes
Jul 16, 2020
jklymak
left a comment
Member
There was a problem hiding this comment.
I think this is an improved error message.
QuLogic
reviewed
Jul 18, 2020
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
timhoffm
approved these changes
Jul 27, 2020
Member
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #12198. This now errors if a non-float value is provided for xmin/xmax or ymin/ymax to ax{v,h}{line,span}. This should get an API change or a what's new, but I'm not sure which, could someone advise?