104 5

3D Data visualization

plt, pd, sns, faceting, boxplot, pairplot, scatter, scatterplot, density plot
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
# Pairplot (image in comments) g = sns.pairplot(train[selectedCols], hue='target', palette = 'seismic', size=1.2, diag_kind = 'kde',diag_kws=dict(shade=True), plot_kws=dict(s=10)) g.set(xticklabels=[]) ### # Boxplot faceted for 2nd dim and grouped for 3rd dim (image in comments) sns.boxplot(x="facetCol", y="boxplotCol", hue="hueCol", data=df) ### # 1st dim facet, 2nd and 3rd dims are the scatter plot # the hue dimension is used to give statistical info of the y axis var # We discretize the facet variable to have a finite number of facets # We discretize the y axis variable to then show the quartiles in the plot # Image in comments df['discreteFacetVar'] = pd.qcut(df['facetVar'], q=quantile_list, labels=quantile_labels) df['discreteYaxisVar'] = pd.qcut(df['yaxisVar'], q=quantile_list, labels=quantile_labels) g = sns.FacetGrid(df, col="discreteFacetVar", hue='discreteYaxisVar'), "xaxisVar", "yaxisVar", alpha=.7) ### # Like scatterplot but showing density. Scatter plot 2.0 # 3rd dim is hue, we made a manual hue by plotting twice # each time with a different color # Image in comments plot1 = sns.kdeplot(df1['col1'], df1['col2'], cmap="YlOrBr", shade=True, shade_lowest=False) plot2 = sns.kdeplot(df2['col1'], df2['col2'], cmap="Reds", shade=True, shade_lowest=False)
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus