Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seaborn heatmap: swap X and Y axes

I am trying to swap X and Y axes on a Seaborn heatmap.

Background: I have a Pandas dataframe, where the indices are timestamps. When I do

df_all = pd.read_csv(args.input)
df_all.set_index(df_all['Timestamp'])
ax = seaborn.heatmap(df_all, linewidth=0.5)
plt.show()

I get a heatmap (yay!) but with the timestamps on Y, and data items on X.

I will be plotting 8 similar heatmaps using the same timestamps (and a lot of other matplotlib with X-axis timestamps), so I'd like to align the timestamps on X-axis, and keep the data items (column labels 0-511) on Y. How can I swap X and Y axes? I don't find anything on the Seaborn documentation to indicate how.

like image 812
TheBick Avatar asked Sep 18 '25 14:09

TheBick


1 Answers

df_all = pd.read_csv(args.input)

df_all_transposed = df_all.transpose()

pandas dataframes have the method transpose() available to them: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.transpose.html

like image 57
pythomatic Avatar answered Sep 20 '25 03:09

pythomatic