To transpose the axis of a single column heatmap using Seaborn in Python, you can use the heatmap
function with the following parameters:
data
: the data to be plottedx
: the column that will be plotted on the x-axisy
: the column that will be plotted on the y-axisannot
: whether to annotate each cell with its valuecmap
: the color map to use for the heatmapTo transpose the axis of a single column heatmap, simply switch the x
and y
parameters in the heatmap
function, like this:
import seaborn as sns
import matplotlib.pyplot as plt
# Load example dataset
flights = sns.load_dataset("flights")
# Transpose the axis of the heatmap
sns.heatmap(data=flights.pivot('month', 'year', 'passengers'), annot=True, cmap="YlGnBu")
plt.show()
In this example, we are using the flights
dataset and transposing the axis of the passengers
column. The pivot
function is used to reshape the flights
dataset so that the months are on the x-axis and the years are on the y-axis. The heatmap is then plotted with annotations and the YlGnBu
color map.
Asked: 2023-01-12 11:00:00 +0000
Seen: 8 times
Last updated: Oct 15 '22