Description
Bug summary
When ploting using axes errorbar, if the user defines either a x or y error and dashes at the same time the following error is shown: "ValueError: Do not know how to convert [1, 1] to dashes".
The problem disappears if the yerr or xerr arguments are leaved empty. This issue wasn't present on previous versions of matplotlib.
The sample code is the "line_demo_dash_control.py" but with the added yerr.
Code for reproduction
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 500)
y = np.sin(x)
fig, ax = plt.subplots()
# Using set_dashes() to modify dashing of an existing line
line1, = ax.plot(x, y, label='Using set_dashes()')
line1.set_dashes([2, 2, 10, 2]) # 2pt line, 2pt break, 10pt line, 2pt break
# Using plot(..., dashes=...) to set the dashing when creating a line
line2 = ax.errorbar(x, y - 0.2, np.zeros(len(x))+.01, dashes=[1,1], label='Using the dashes parameter')
ax.legend()
plt.show()
Actual outcome
Traceback (most recent call last):
File "/Users/USER/Library/Python/3.8/lib/python/site-packages/matplotlib/collections.py", line 630, in set_linestyle
dashes = [mlines._get_dash_pattern(ls)]
File "/Users/USER/Library/Python/3.8/lib/python/site-packages/matplotlib/lines.py", line 50, in _get_dash_pattern
raise ValueError(f'Unrecognized linestyle: {style!r}')
ValueError: Unrecognized linestyle: [1, 1]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/USER/Library/Python/3.8/lib/python/site-packages/matplotlib/collections.py", line 632, in set_linestyle
dashes = [mlines._get_dash_pattern(x) for x in ls]
File "/Users/USER/Library/Python/3.8/lib/python/site-packages/matplotlib/collections.py", line 632, in
dashes = [mlines._get_dash_pattern(x) for x in ls]
File "/Users/USER/Library/Python/3.8/lib/python/site-packages/matplotlib/lines.py", line 50, in _get_dash_pattern
raise ValueError(f'Unrecognized linestyle: {style!r}')
ValueError: Unrecognized linestyle: 1
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "line_demo_dash_control.py", line 34, in
line2 = ax.errorbar(x, y - 0.2, np.zeros(len(x))+.01, dashes=[1,1], label='Using the dashes parameter')
File "/Users/USER/Library/Python/3.8/lib/python/site-packages/matplotlib/init.py", line 1412, in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)
File "/Users/USER/Library/Python/3.8/lib/python/site-packages/matplotlib/axes/_axes.py", line 3467, in errorbar
barcols.append(lines_func(
File "/Users/USER/Library/Python/3.8/lib/python/site-packages/matplotlib/init.py", line 1412, in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)
File "/Users/USER/Library/Python/3.8/lib/python/site-packages/matplotlib/axes/_axes.py", line 1139, in vlines
lines.update(kwargs)
File "/Users/USER/Library/Python/3.8/lib/python/site-packages/matplotlib/artist.py", line 1066, in update
ret.append(func(v))
File "/Users/USER/Library/Python/3.8/lib/python/site-packages/matplotlib/cbook/init.py", line 1845, in method
return getattr(self, name)(*args, **kwargs)
File "/Users/USER/Library/Python/3.8/lib/python/site-packages/matplotlib/collections.py", line 635, in set_linestyle
raise ValueError('Do not know how to convert {!r} to '
ValueError: Do not know how to convert [1, 1] to dashes
Expected outcome
Two dashed lines. One with y errors.
Additional information
No response
Operating system
MacOS 11.6.3
Matplotlib Version
3.5.1
Matplotlib Backend
MacOSX
Python version
3.8.9
Jupyter version
No response
Installation
pip