In [1]:
import numpy as pd
import pandas as pd
In [4]:
import matplotlib as plt
import seaborn as sns
In [6]:
days=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
temperature=[36.4,37,39,39.4,45,42.6,33.5,43,42.5,45,46,46.7,41.5,43.6,41.7]
sns.lineplot(x=days,y=temperature)
Out[6]:
In [7]:
#above is the line plot by saeborn
In [11]:
days=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
temperature=[36.4,37,39,39.4,45,42.6,33.5,43,42.5,45,46,46.7,41.5,43.6,41.7]
temp_df=pd.DataFrame({"days":days,"temperature":temperature})
sns.lineplot(x="days",y="temperature",data=temp_df)
Out[11]:
In [12]:
#above is plotting in dataframe
In [13]:
tips=sns.load_dataset('tips')
In [14]:
print(tips)
In [15]:
tips.head()
Out[15]:
In [16]:
tips.info()
In [17]:
#.info() will all the information regarding dataframe
In [18]:
tips['total_bill']
Out[18]:
In [19]:
#you can print any column as seen in the above example
In [20]:
tips['total_bill'].max()
Out[20]:
In [21]:
#finding the maximum bill as above
In [22]:
tips[tips['total_bill']==50.81]
Out[22]:
In [23]:
tips['time'].value_counts()
Out[23]:
In [24]:
tips['size'].value_counts()
Out[24]:
In [25]:
#now we will do seaborn plotting using line
In [26]:
sns.lineplot(x='total_bill',y='tip',data=tips)
Out[26]:
In [27]:
sns.lineplot(x='size',y='tip',data=tips)
Out[27]:
In [28]:
#in the above 2 examples data=tips is the dataframe used for plotting the line graph
In [29]:
sns.lineplot(x='size',y='total_bill',data=tips)
Out[29]:
In [30]:
sns.lineplot(x='size',y='tip',data=tips,hue='time')
Out[30]:
In [31]:
#hue is an attribute of seaborn line plot. so inthe above example, it divivdes it to lunch and dinner
In [32]:
sns.lineplot(x='size',y='tip',data=tips,hue='time', style='time')
Out[32]:
In [33]:
#style makes one line different. like in the above example
In [34]:
sns.lineplot(x='size',y='tip',data=tips,hue='time', style='time',palette='Accent')
Out[34]:
In [35]:
#palette changes the colour, the following values can be used instead of accent with palette Accent, Accent_r, Blues, Blues_r, BrBG, BrBG_r, BuGn, BuGn_r, BuPu, BuPu_r, CMRmap, CMRmap_r, Dark2, Dark2_r, GnBu, GnBu_r, Greens, Greens_r, Greys, Greys_r, OrRd, OrRd_r, Oranges, Oranges_r, PRGn, PRGn_r, Paired, Paired_r, Pastel1, Pastel1_r, Pastel2, Pastel2_r, PiYG, PiYG_r, PuBu, PuBuGn, PuBuGn_r, PuBu_r, PuOr, PuOr_r, PuRd, PuRd_r, Purples, Purples_r, RdBu, RdBu_r, RdGy, RdGy_r, RdPu, RdPu_r, RdYlBu, RdYlBu_r, RdYlGn, RdYlGn_r, Reds, Reds_r, Set1, Set1_r, Set2, Set2_r, Set3, Set3_r, Spectral, Spectral_r, Wistia, Wistia_r, YlGn, YlGnBu, YlGnBu_r, YlGn_r, YlOrBr, YlOrBr_r, YlOrRd, YlOrRd_r, afmhot, afmhot_r, autumn, autumn_r, binary, binary_r, bone, bone_r, brg, brg_r, bwr, bwr_r, cividis, cividis_r, cool, cool_r, coolwarm, coolwarm_r, copper, copper_r, cubehelix, cubehelix_r, flag, flag_r, gist_earth, gist_earth_r, gist_gray, gist_gray_r, gist_heat, gist_heat_r, gist_ncar, gist_ncar_r, gist_rainbow, gist_rainbow_r, gist_stern, gist_stern_r, gist_yarg, gist_yarg_r, gnuplot, gnuplot2, gnuplot2_r, gnuplot_r, gray, gray_r, hot, hot_r, hsv, hsv_r, icefire, icefire_r, inferno, inferno_r, jet, jet_r, magma, magma_r, mako, mako_r, nipy_spectral, nipy_spectral_r, ocean, ocean_r, pink, pink_r, plasma, plasma_r, prism, prism_r, rainbow, rainbow_r, rocket, rocket_r, seismic, seismic_r, spring, spring_r, summer, summer_r, tab10, tab10_r, tab20, tab20_r, tab20b, tab20b_r, tab20c, tab20c_r, terrain, terrain_r, twilight, twilight_r, twilight_shifted, twilight_shifted_r, viridis, viridis_r, vlag, vlag_r, winter, winter_r
In [37]:
sns.lineplot(x='size',y='tip',data=tips,hue='time', style='time',palette='Accent')
Out[37]:
In [38]:
sns.lineplot(x='size',y='tip',data=tips,hue='time', style='time',palette=['red','blue'])
Out[38]:
In [39]:
sns.lineplot(x='size',y='tip',data=tips,hue='time', style='time',palette=['red','blue'],hue_order=['Dinner','Lunch'])
Out[39]:
In [40]:
#hue_order=['Dinner','Lunch']) commands let you define if its luch or diner or car or anything else
In [41]:
sns.lineplot(x='size',y='tip',data=tips,hue='time', style='time',palette=['red','blue'], dashes=False)
Out[41]:
In [42]:
#to remove dashes in the line, we use the above command dashes=False
In [43]:
sns.lineplot(x='size',y='tip',data=tips,hue='time', style='time',palette=['red','blue'],markers=['o','^'])
Out[43]:
In [44]:
#in the above example we put markers
In [45]:
sns.lineplot(x='size',y='tip',data=tips,hue='time', style='time',palette=['red','blue'],markers=['o','^'],legend=False)
Out[45]:
In [46]:
#in the above example we removed the legends
In [47]:
sns.lineplot(x='size',y='tip',data=tips,hue='time', style='time',palette=['red','blue'],markers=['o','^'])
plt.title('Line Plot')
plt.xlabel("Size")
plt.ylabel("Tip")
plt.show()
In [ ]:
No comments:
Post a Comment