-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
By using pandas I try to visualize the selection frame I have got from my data frame df here below. I can not understand why seaborn via matplotlib displays strange colorful dots for the class car. In my opinion this problem should be related to the bug 5377. If I remove this class I get the same problem in another one. Do you know how I can fix it? Apparently this issue occurs only on my laptop.
When I run this code on python I get the following message:
/usr/lib/python3/dist-packages/matplotlib/init.py:874: UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter.
warnings.warn(self.msg_depr % (key, alt_key))
For more details please have a look at this Page
I tried to use the following solutions but they did not give me the right results.
- from matplotlib.colors import rgb2hex (as suggested in 5377 issue but it did not work out)
- plt.rcParams['image.cmap'] = 'gray' (as suggested in 5377 issue but it did not work out)
- plt.rc('lines', linewidth=4)
plt.rc('axes', prop_cycle=(cycler('color', ['r', 'g', 'b', 'y']) +
cycler('linestyle', ['-', '--', ':', '-.']))) (a suggested in link)
Code for reproduction
import pandas as pd
import numpy as np
import random
from cycler import cycler
from matplotlib import pyplot as plt
#from matplotlib.colors import rgb2hex
import seaborn as sns
np.random.seed(176)
random.seed(16)
df = pd.DataFrame({'class': rando
68C1
m.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()
print(frame)
yaplot=sns.lmplot(x='Year' , y='Amount', data=frame, hue='class',palette='Set1', 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()
Output of my ipython3:
In [1]: %run StackOverFlow-Answer-ScatterPlotwithFORFinal.py
/usr/lib/python3/dist-packages/matplotlib/__init__.py:874: UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter.
warnings.warn(self.msg_depr % (key, alt_key))
class Year Amount
0 bathroom 2014 16.453632
1 bathroom 2015 40.407985
2 bathroom 2016 63.377911
3 bathroom 2017 98.786027
4 car 2010 22.252528
5 car 2012 127.597498
6 car 2015 93.694632
7 dining room 2010 54.077396
8 dining room 2011 15.844124
9 dining room 2012 36.273090
10 dining room 2014 27.156423
11 kitchen 2010 69.254971
12 kitchen 2013 88.100901
13 kitchen 2016 86.370960
14 kitchen 2017 95.764052
15 living room 2010 53.252083
16 living room 2011 94.708138
17 living room 2015 78.666517
18 living room 2016 21.260494
19 office 2012 35.743781
pd.show_versions()
python: 3.5.2.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-83-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.20.3
pytest: None
pip: 8.1.1
setuptools: None
Cython: None
numpy: 1.13.1
scipy: 0.17.0
xarray: None
IPython: 2.4.1
sphinx: None
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: 3.2.2
numexpr: 2.6.2
feather: None
matplotlib: 1.5.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.4.1
html5lib: 0.999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
s3fs: None
pandas_gbq: None
pandas_datareader: None