Skip to content
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

BUG: allow facecolors to be overridden in LineCollection #4958

Merged
merged 2 commits into from Aug 19, 2015

Conversation

jakevdp
Copy link
Contributor

@jakevdp jakevdp commented Aug 19, 2015

Very small change, fully backward compatible.

Current behavior is this:

import matplotlib.pyplot as plt
from matplotlib.collections import LineCollection
import numpy as np

points = np.random.rand(5, 3, 2)
colors = plt.cm.jet(np.linspace(0, 1, 5))
coll = LineCollection(points, facecolors=colors)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-66-7da275dddf5c> in <module>()
      5 points = np.random.rand(5, 3, 2)
      6 colors = plt.cm.jet(np.linspace(0, 1, 5))
----> 7 coll = LineCollection(points, facecolors=colors)

/Users/jakevdp/anaconda/envs/py3k/lib/python3.3/site-packages/matplotlib/collections.py in __init__(self, segments, linewidths, colors, antialiaseds, linestyles, offsets, transOffset, norm, cmap, pickradius, zorder, **kwargs)
   1081             pickradius=pickradius,
   1082             zorder=zorder,
-> 1083             **kwargs)
   1084 
   1085         self.set_segments(segments)

TypeError: __init__() got multiple values for keyword argument 'facecolors'

@@ -1106,6 +1107,9 @@ def __init__(self, segments, # Can be None.
*zorder*
The zorder of the LineCollection. Default is 2

*facecolors*
The facecolors of the LineCollection. Default is 'none'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a quick little explanation of what it means for a line collection to have a facecolor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@jakevdp
Copy link
Contributor Author

jakevdp commented Aug 19, 2015

I should add: the reason this is useful is that you can use line collections to draw filled polygons from vertices alone, without the need to explicitly wrap each set of vertices in a Path as in, e.g. PathCollection. My current workaround is:

coll = LineCollection(points)
coll.set_facecolors(colors)

which works, but it took a bit of digging to figure out why LineCollection was telling me I passed facecolors twice in the more intuitive use above.

@WeatherGod
Copy link
Member

Correct. It can just a little non-obvious that a LineCollection can have a facecolor. Will merge once Travis is happy.

WeatherGod added a commit that referenced this pull request Aug 19, 2015
BUG: allow facecolors to be overridden in LineCollection
@WeatherGod WeatherGod merged commit 6b32d22 into matplotlib:master Aug 19, 2015
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 this pull request may close these issues.

None yet

3 participants