0

I would like to visualize the selection frame I have got from my data frame df. I can not understand why seaborn seems to have some problems plotting the class named car. In the figure I obtain there are two black dots and a white one referring to this class instead of 3 blue dots as the legend reports. Actually, if I remove this class I get the same problem in another one. Do you know why? Thanks in advance.

Here my code:

import pandas as pd
import numpy as np
import random 
from matplotlib import pyplot as plt 
import seaborn as sns

np.random.seed(176)
random.seed(16)

df = pd.DataFrame({'class': random.sample(['living room','dining room','kitchen','car','bathroom','office']*10, k=25),
               'Amount': np.random.sample(25)*100,
               'Year': random.sample(list(range(2010,2018))*50, k=25),
               'Month': random.sample(list(range(1,12))*100, k=25)})


frame = pd.pivot_table(df, index=['class','Year'], values=['Amount'], aggfunc=np.sum).reset_index()
yaplot=sns.lmplot(x='Year' , y='Amount', data=frame, hue='class',palette='hls', fit_reg=False,size= 5, aspect=5/3, legend=False,legend_out=False,scatter_kws={'s': 70})
yaplot.ax.legend(loc=2)
sns.plt.ticklabel_format(style='plain', axis='x',useOffset=False)
plt.show()

Here my result:

enter image description here

Here my frame (Sorry for this informal way to share it. I wanted to upload the csv file of it but I just found out it is not possible to do it) :

enter image description here

Up-To-Date:

I get the following warning when I run the code. I did not see it before.

UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter

Actually it makes sense. My code seems to have some problems only when it has to use colors. To avoid it, I added the two lines:

plt.rc('axes', prop_cycle=(cycler('color', ['b', 'g', 'r', 'c', 'm', 'y', 'k'])))  

but nothing has changed.

Any ideas? Should I reinstall anything to get out of my issue? and if yes, what?

fdrigo
  • 191
  • 1
  • 4
  • 14
  • The [plot I get when running your code](https://i.stack.imgur.com/dD6u2.png) is significantly different from yours. So on the one hand, the data seems different and on the other hand, the issue you report about not showing the class correctly is not present. – ImportanceOfBeingErnest Jul 16 '17 at 11:43
  • Have you run my code? I do not why I keep obtaining the same figure. I also added what the terminal gave me as frame (photo above) which disagree with your plot.. – fdrigo Jul 16 '17 at 12:34
  • @ImportanceOfBeingErnest – fdrigo Jul 17 '17 at 06:51
  • During my research I bumped into the websites: https://github.com/matplotlib/matplotlib/issues/6395/ https://github.com/matplotlib/matplotlib/issues/5854/ https://stackoverflow.com/questions/33792478/how-to-suppress-matplotlib-warning – fdrigo Jul 18 '17 at 08:56
  • Now it runs correctly. The problem was that I was running the code with a old version seaborn. – fdrigo Jul 21 '17 at 13:39

0 Answers0