TheBick
TheBick

Reputation: 351

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.

Upvotes: 4

Views: 17199

Answers (1)

pythomatic
pythomatic

Reputation: 657

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

Upvotes: 5

Related Questions