Posts

Showing posts with the label Seaborn

Boxplot Of Multiple Columns Of A Pandas Dataframe On The Same Figure (seaborn)

Image
Answer : The seaborn equivalent of df.boxplot() is sns.boxplot(x="variable", y="value", data=pd.melt(df)) Complete example: import numpy as np; np.random.seed(42) import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = pd.DataFrame(data = np.random.random(size=(4,4)), columns = ['A','B','C','D']) sns.boxplot(x="variable", y="value", data=pd.melt(df)) plt.show() This works because pd.melt converts a wide-form dataframe A B C D 0 0.374540 0.950714 0.731994 0.598658 1 0.156019 0.155995 0.058084 0.866176 2 0.601115 0.708073 0.020584 0.969910 3 0.832443 0.212339 0.181825 0.183405 to long-form variable value 0 A 0.374540 1 A 0.156019 2 A 0.601115 3 A 0.832443 4 B 0.950714 5 B 0.155995 6 B 0.708073 7 B 0.212339 8 C 0.731994 9 C ...

Change Xticklabels Fontsize Of Seaborn Heatmap

Image
Answer : Consider calling sns.set(font_scale=1.4) before plotting your data. This will scale all fonts in your legend and on the axes. My plot went from this, To this, Of course, adjust the scaling to whatever you feel is a good setting. Code: sns.set(font_scale=1.4) cmap = sns.diverging_palette(h_neg=210, h_pos=350, s=90, l=30, as_cmap=True) sns.clustermap(data=corr, annot=True, fmt='d', cmap="Blues", annot_kws={"size": 16}) Or just use the set_xticklabels: g = sns.clustermap(data=corr_s, annot=True, fmt='d',cmap = "Blues") g.ax_heatmap.set_xticklabels(g.ax_heatmap.get_xmajorticklabels(), fontsize = 16) To get different colors for the ticklabels: import matplotlib.cm as cm colors = cm.rainbow(np.linspace(0, 1, corr_s.shape[0])) for i, ticklabel in enumerate(g.ax_heatmap.xaxis.get_majorticklabels()): ticklabel.set_color(colors[i])

Changing Color And Marker Of Each Point Using Seaborn Jointplot

Image
Answer : Solving this problem is almost no different than that from matplotlib (plotting a scatter plot with different markers and colors), except I wanted to keep the marginal distributions: import seaborn as sns from itertools import product sns.set(style="darkgrid") tips = sns.load_dataset("tips") color = sns.color_palette()[5] g = sns.jointplot("total_bill", "tip", data=tips, kind="reg", stat_func=None, xlim=(0, 60), ylim=(0, 12), color='k', size=7) #Clear the axes containing the scatter plot g.ax_joint.cla() #Generate some colors and markers colors = np.random.random((len(tips),3)) markers = ['x','o','v','^','<']*100 #Plot each individual point separately for i,row in enumerate(tips.values): g.ax_joint.plot(row[0], row[1], color=colors[i], marker=markers[i]) g.set_axis_labels('total bill', 'tip', fontsize=16) Which gives me this: ...