Skip to content
Advertisement

How to plot a column value with its index as axis

I have a data frame df:

JavaScript

In reality, I have 50 rows in the data frame. To make it simple I am representing it here with only 3 rows.

I am interested in illustrating the correlation between ColumnA and ColumnB that is given in df['correlation']. What would be the best possible way to do so?

One of the choices may be to plot a plot of this kind:

enter image description here

However, I am not sure how to plot the same using matplotlib or any other python module. Also, how to keep only one axis on the plot. For instance, keep only ColumnA axis on the left as it is and remove ColumnB axis from the right.

Other suggestions to represent the same in a better way are welcome.

Advertisement

Answer

Using sns.heatmap we can plot a single column heatmap and then tweak the y-axes to put the additional labels on:

JavaScript

Single column heatmap with secondary y-axis


If you want to reverse the colour map you can set cmap="rocket_r" in the sns.heatmap function call.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement