Skip to content

[Bug]: ValueError: Do not know how to convert "list" to dashes; when using axes errorbar. #22590

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

Closed
JNaokiDKondo opened this issue Mar 3, 2022 · 1 comment · Fixed by #22594
Milestone

Comments

@JNaokiDKondo
Copy link

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

@tacaswell tacaswell added this to the v3.6.0 milestone Mar 3, 2022
@tacaswell tacaswell added Good first issue Open a pull request against these issues if there are no active ones! and removed Good first issue Open a pull request against these issues if there are no active ones! labels Mar 3, 2022
@tacaswell tacaswell modified the milestones: v3.6.0, v3.5.2 Mar 3, 2022
@tacaswell
Copy link
Member

The issue looks like the the Collection class (which we use of the error bars) do not know how to deal with dashes.

In the process of trying to write up an explanation of how to fix this, I sorted out how to fix it and it is less work to open a PR doing it than to explain, PR in a few minutes.


Thank you for the very good bug report @JNaokiDKondo !

tacaswell added a commit to tacaswell/matplotlib that referenced this issue Mar 3, 2022
*dashes* is another Line2D only kwarg that should not be passed to all of the
artists created.

closes matplotlib#22590
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 a pull request may close this issue.

2 participants