python - Seaborn heatmap by column -


it seems me heatmap function applied dataframe in entirety. if want heatmap applied given set of column(s) dataset? imagine can achieved smartly using cmap, cannot seem work.

pass desired sub-dataframe seaborn.heatmap:

seaborn.heatmap(df[[col1, col2]], ...) 

df[[col1, col2, ..., coln]] returns dataframe composed of columns col1, col2, ... coln df. note double brackets.


if wish highlight values , plot heatmap though other values zero, make copy of dataframe , set values 0 before calling heatmap. example, modifying the example docs,

import numpy np import matplotlib.pyplot plt import seaborn sns import seaborn.matrix smatrix  sns.set()  flights_long = sns.load_dataset("flights") flights = flights_long.pivot("month", "year", "passengers") flights = flights.reindex(flights_long.iloc[:12].month)  columns = [1953,1955] myflights = flights.copy() mask = myflights.columns.isin(columns) myflights.loc[:, ~mask] = 0 arr = flights.values vmin, vmax = arr.min(), arr.max() sns.heatmap(myflights, annot=true, fmt="d", vmin=vmin, vmax=vmax) plt.show() 

yields

enter image description here


Comments

Popular posts from this blog

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

python - How to remove the Xframe Options header in django? -