Skip to content

plt.errorbar raises error when given marker=<matplotlib.markers.MarkerStyle object> #18600

Closed
@evanberkowitz

Description

@evanberkowitz

Bug report

Bug summary

plt.errorbar( ..., marker=<matplotlib.markers.MarkerStyle object>) raises a `TypeError: float() argument must be a string or a number, not 'MarkerStyle' unexpectedly.

Code for reproduction

#!/usr/bin/env python3

import matplotlib
import matplotlib.pyplot as plt
from matplotlib.markers import MarkerStyle

print(f"{matplotlib.__version__=}")
print(matplotlib.get_backend())

# I want to use this marker in an errorbar plot
m = MarkerStyle("D")
m._transform.scale(1.0, 0.6)
print(m)

# I can use it in a scatter plot
fig, ax = plt.subplots()
plt.scatter([1,2,3],[1,2,3], s=225, marker="d")
plt.scatter([1,2,3],[2,3,4], s=225, marker=m, color="crimson")
plt.errorbar([1,2,3],[3,4,5], yerr=[0.5,0.5,0.5], marker='o', linestyle='none', color='green')
plt.show()
# which produces a figure similar to https://stackoverflow.com/a/49662571/

# But when I use it in errorbar
fix, ax = plt.subplots()
plt.errorbar([1,2,3],[3,4,5], yerr=[0.5,0.5,0.5], marker=m, linestyle='none', color='green')
plt.show()

Actual outcome

The first figure is produced with a correctly-rotated marker, similar to this Stack Overflow answer, which looks like this:

Figure_1

After closing the first figure, the second figure, in contrast, gives an error.

> ./example.py
matplotlib.__version__='3.2.2'
<matplotlib.markers.MarkerStyle object at 0x106e89d00>
Traceback (most recent call last):
  File "./example.py", line 25, in <module>
    plt.errorbar([1,2,3],[3,4,5], yerr=[0.5,0.5,0.5], marker=m, color='green')
  File "/usr/local/lib/python3.8/site-packages/matplotlib/pyplot.py", line 2524, in errorbar
    return gca().errorbar(
  File "/usr/local/lib/python3.8/site-packages/matplotlib/__init__.py", line 1565, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
  File "/usr/local/lib/python3.8/site-packages/matplotlib/axes/_axes.py", line 3265, in errorbar
    data_line = mlines.Line2D(x, y, **plot_line_style)
  File "/usr/local/lib/python3.8/site-packages/matplotlib/lines.py", line 378, in __init__
    self._marker = MarkerStyle(marker, fillstyle)
  File "/usr/local/lib/python3.8/site-packages/matplotlib/markers.py", line 225, in __init__
    self.set_marker(marker)
  File "/usr/local/lib/python3.8/site-packages/matplotlib/markers.py", line 289, in set_marker
    Path(marker)
  File "/usr/local/lib/python3.8/site-packages/matplotlib/path.py", line 127, in __init__
    vertices = _to_unmasked_float_array(vertices)
  File "/usr/local/lib/python3.8/site-packages/matplotlib/cbook/__init__.py", line 1317, in _to_unmasked_float_array
    return np.asarray(x, float)
  File "/usr/local/lib/python3.8/site-packages/numpy/core/_asarray.py", line 83, in asarray
    return array(a, dtype, copy=False, order=order)
TypeError: float() argument must be a string or a number, not 'MarkerStyle'

Expected outcome

The second figure should show a sequence of diamonds that are the thin_diamond marker but rotated 90˚ (so that it's wider than it is tall), like the red diamonds in the first figure, but with error bars of width 0.5 (like the green circles in the first figure).

Matplotlib version

  • Operating system: macOS Catalina 10.15.6
  • Matplotlib version: 3.2.2
  • Matplotlib backend (print(matplotlib.get_backend())): MacOSX
  • Python version: 3.8.5
  • Jupyter version (if applicable):
  • Other libraries:

Installed mpl via pip3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions