Skip to content

eventplot: allow a list of alpha channels as in the case with colors #19376

Closed

Description

@dizcza

I'm not sure if it's a bug or a feature. It's both.

>>> plt.eventplot([[0, 1, 2], [0.5, 2.3]], color=['r', 'g'])

works while

>>> plt.eventplot([[0, 1, 2], [0.5, 2.3]], alpha=[0.5, 0.2])

throws an error

Traceback (most recent call last):
  File "/home/ulianych/anaconda3/envs/viziphant/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3319, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-fab7f3737c6e>", line 1, in <module>
    plt.eventplot([[0, 1, 2], [0.5, 2.3]], alpha=[0.5, 0.2])
  File "/home/ulianych/anaconda3/envs/viziphant/lib/python3.7/site-packages/matplotlib/pyplot.py", line 2622, in eventplot
    **({"data": data} if data is not None else {}), **kwargs)
  File "/home/ulianych/anaconda3/envs/viziphant/lib/python3.7/site-packages/matplotlib/__init__.py", line 1447, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
  File "/home/ulianych/anaconda3/envs/viziphant/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 1480, in eventplot
    coll.update(kwargs)
  File "/home/ulianych/anaconda3/envs/viziphant/lib/python3.7/site-packages/matplotlib/artist.py", line 998, in update
    ret.append(func(v))
  File "/home/ulianych/anaconda3/envs/viziphant/lib/python3.7/site-packages/matplotlib/collections.py", line 834, in set_alpha
    super().set_alpha(alpha)
  File "/home/ulianych/anaconda3/envs/viziphant/lib/python3.7/site-packages/matplotlib/artist.py", line 930, in set_alpha
    raise TypeError('alpha must be a float or None')
TypeError: alpha must be a float or None

matplotlib v3.3.3
Python 3.7.6

Activity

  1. mwaskom commented on Jan 27, 2021

    @mwaskom

    You can pass colors as rgba values, so like

    from matplotlib.colors import to_rgba
    plt.eventplot([[0, 1, 2], [0.5, 2.3]], color=[to_rgba('r', .5), to_rgba('g', .2)])

    should do it

  2. dizcza commented on Jan 27, 2021

    @dizcza
    Author

    But I don't want to specify the colors.
    -_-

  3. Moritz-Alexander-Kern commented on Nov 3, 2022

    @Moritz-Alexander-Kern

    This is solved ?

    Running:

    plt.eventplot([[0, 1, 2], [0.5, 2.3]], alpha=[0.5, 0.2])

    produces the following plot:
    Figure_1

    Python: 3.8.10
    matplotlib: 3.6.2

  4. timhoffm commented on Nov 4, 2022

    @timhoffm
    Member

    This got fixed as a side effect of #22451.

  5. added this to the v3.6.0 milestone on Nov 4, 2022
  6. mwaskom commented on Nov 5, 2022

    @mwaskom

    Is that example the expected behavior? I would expect the top row to both be 0.5 and the bottom row to all be 0.2.

  7. timhoffm commented on Nov 11, 2022

    @timhoffm
    Member

    You are right, the behavior was modified (likely unintendedly). While this was raising before, the alpha sequence is now cycling within each dataset / LineCollection. We instead want to sequentially take the alpha values one value per LineCollection.

    This needs explicit handling at

    for position, lineoffset, linelength, linewidth, color, linestyle in \
    zip(positions, lineoffsets, linelengths, linewidths,
    colors, linestyles):
    coll = mcoll.EventCollection(position,
    orientation=orientation,
    lineoffset=lineoffset,
    linelength=linelength,
    linewidth=linewidth,
    color=color,
    linestyle=linestyle)

  8. modified the milestones: v3.6.0, v3.7.0 on Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions