Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide Axis Titles in Seaborn

Given the following heatmap, how would I remove the axis titles ('month' and 'year')?

import seaborn as sns  # Load the example flights dataset and conver to long-form flights_long = sns.load_dataset("flights") flights = flights_long.pivot("month", "year", "passengers")  # Draw a heatmap with the numeric values in each cell sns.heatmap(flights, annot=True, fmt="d", linewidths=.5) 

current graph

like image 487
Dance Party2 Avatar asked Dec 14 '15 19:12

Dance Party2


People also ask

How do you hide the Y axis in Python?

How to hide axis in matplotlib figure? The matplotlib. pyplot. axis('off') command us used to hide the axis(both x-axis & y-axis) in the matplotlib figure.

How do I hide axes in matplotlib?

MatPlotLib with Python Plot x and y points using the plot() method with linestyle, labels. To hide the grid, use plt. grid(False).


1 Answers

Before calling sns.heatmap, get the axes using plt.subplots, then use set_xlabel and set_ylabel. For example:

import seaborn as sns import matplotlib.pyplot as plt  # Load the example flights dataset and conver to long-form flights_long = sns.load_dataset("flights") flights = flights_long.pivot("month", "year", "passengers")  # ADDED: Extract axes. fig, ax = plt.subplots(1, 1, figsize = (15, 15), dpi=300)  # Draw a heatmap with the numeric values in each cell sns.heatmap(flights, annot=True, fmt="d", linewidths=.5)  # ADDED: Remove labels. ax.set_ylabel('')     ax.set_xlabel('') 

New graph

like image 64
Dance Party2 Avatar answered Sep 18 '22 14:09

Dance Party2