Home>
How to output multiple images in seaborn

Create heatmaps with Python, pandas, seaborn I wrote the following code as a reference.

import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
fig, axes = plt.subplots (nrows = 2, ncols = 3, figsize = (10, 10))
list_2d = [[0, 1, 2], [3, 4, 5]]
arr_2d = np.arange (-8, 8) .reshape ((4, 4))
sns.heatmap (list_2d, ax = axes [0, 0])
sns.heatmap (arr_2d, ax = axes [1, 2])


When executed, the following image was output.
However, this rectangular image is very disturbing. (The rectangular image here is
4 rectangles with empty margins and their values. )
Is there a way to display 2 rows and 3 columns without displaying this rectangular image?

I'm sorry to tell you.

  • Answer # 1

    Axes instance.axis ("off")

    matplotlib.axes.Axes.axis — Matplotlib 3.1.0 documentation

    Make the axes white with matplotlib (hide the x-axis and y-axis and hide them)-quiet name (拙 Article)

    For question text code,

    for ax in axes.ravel () [1: -1]:
        ax.axis ("off")


    Try adding somewhere (before the result is output).

  • Answer # 2

    This is an answer after understanding "this rectangle" as a color bar.

    fig, axes = plt.subplots (nrows = 2, ncols = 3, figsize = (10, 10))
    list_2d = [[0, 1, 2], [3, 4, 5]]
    arr_2d = np.arange (-8, 8) .reshape ((4, 4))
    sns.heatmap (list_2d, ax = axes [0, 0], cbar = False)
    sns.heatmap (arr_2d, ax = axes [1, 2], cbar = False)