Plotting methods modify color arrays in place #12039

Closed
mwaskom opened this Issue Jan 14, 2016 · 0 comments

Comments

Projects
None yet
2 participants
Contributor

mwaskom commented Jan 14, 2016

Ran into a weird issue where pandas plotting was changing values in color arrays I was passing to it.

Here is a simple example (Pandas 0.17.1; Python 2.7; OSX):

colors = sns.color_palette("Blues", 3)
print len(colors)
pd.DataFrame(np.random.rand(10, 2)).plot(color=colors)
print len(colors)

outputs:

3
5

I've seen various other kinds of changes, including sometimes changing the values but not the length of the color array. A particularly nasty one was where I had taken some actual data and passed it through a matplotlib norm and colormap, and the modifications made their way all the way back up to my data.

I assume this can easily be handled by copying the color array, but I'm not sure.

Sorry if this has been reported...I checked recent issues and didn't see anything, but there are a lot :)

TomAugspurger added this to the 0.18.0 milestone Jan 14, 2016

@TomAugspurger TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue Jan 15, 2016

@TomAugspurger TomAugspurger BUG: .plot modifing `colors` input
Closes pandas-dev#12039

Just added a defensive copy in `_get_standard_colors`
on list-likes.
13bd183
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment