Reputation: 1144
I have a Pandas dataframe ("df
") that looks something like:
Variable1 Var2 Parameters Values
0 10.000 1.1 0.296342 0.170009
1 10.015 1.1 0.297013 0.168656
2 10.030 1.1 0.297659 0.167326
3 10.045 1.1 0.298282 0.166018
4 10.060 1.1 0.298883 0.164731
5 10.075 1.1 0.299462 0.162223
... ... ... ... ...
4038 24.565 1.0 0.563698 0.222069
Pivoting the dataframe using the following commands,
# Pivot dataframe
df = df.pivot('Var2', 'Variable1', 'Values')
I get the below pivoted dataframe:
Variable1 10.000 10.015 10.030 10.045 10.060 10.075 \
Var2
1.0 0.219987 0.218130 0.216290 0.214465 0.212654 0.210856
1.1 0.170009 0.168656 0.167326 0.166018 0.164731 0.163467
1.2 0.133185 0.132202 0.131230 0.130269 0.129318 0.128378
1.3 0.104472 0.103893 0.103312 0.102729 0.102147 0.101564
Variable1 ... 24.865 24.880 24.895 24.910 24.925
Var2 ...
1.0 ... 0.212118 0.211691 0.211272 0.210860 0.210456
1.1 ... 0.174883 0.174566 0.174257 0.173956 0.173662
1.2 ... 0.147406 0.147154 0.146907 0.146664 0.146425
1.3 ... 0.126780 0.126616 0.126456 0.126301 0.126150
However, when I try to image this using Seaborn's heatmap
with the commands:
# Pivot dataframe
df = df.pivot('Var2', 'Variable1', 'Values')
# Create heatmap
f, ax = plt.subplots(figsize=(20, 10))
sns.heatmap(df)
ax.xaxis.set_major_locator(ticker.MultipleLocator(20))
ax.xaxis.set_major_formatter(ticker.ScalarFormatter())
plt.show()
I am getting a plot that shows the indices of Variable1 (0,1,2,3,4,...) whereas I need it to display the values of Variable1 (10, 10.015, 10.030, 10.045, etc.). I have included an example to illustrate.
What am I missing?
Upvotes: 0
Views: 1092
Reputation: 5706
Copying your sample data,
Variable1 Var2 Parameters Values
0 10.000 1.1 0.296342 0.170009
1 10.015 1.1 0.297013 0.168656
2 10.030 1.1 0.297659 0.167326
3 10.045 1.1 0.298282 0.166018
4 10.060 1.1 0.298883 0.164731
5 10.075 1.1 0.299462 0.162223
4038 24.565 1.0 0.563698 0.222069
df = pd.read_clipboard()
df = df.pivot('Var2', 'Variable1', 'Values')
How df
looks like:
Variable1 10.000 10.015 10.030 10.045 10.060 10.075 \
Var2
1.0 NaN NaN NaN NaN NaN NaN
1.1 0.170009 0.168656 0.167326 0.166018 0.164731 0.162223
Variable1 24.565
Var2
1.0 0.222069
1.1 NaN
just using sns.heatmap(df)
returns,
Upvotes: 1