如何在不擦除内容的情况下擦除matplotlib中的轴线?

How to erase the axis lines in matplotlib without erasing contents?

下图中,我想擦除右上图中的x轴和y轴,如何不擦除文字?

我试过:

axes[m,k].get_yaxis().set_visible(False)
axes[m,k].get_xaxis().set_visible(False)

但它并没有做到。

您可以使用

关闭坐标轴
ax.axis("off")


使用 seaborn 的示例 PairGrid:

import seaborn.apionly as sns
import matplotlib.pyplot as plt

df = sns.load_dataset("iris")
g = sns.PairGrid(df, hue="species")

g.map_lower(sns.kdeplot, cmap="Blues_d")
g.map_diag(sns.kdeplot, lw=3, legend=False)

def text(x,y, color, label):
    i = ["setosa", "versicolor","virginica"].index(label)
    xm = x.mean(); ym = y.mean()
    tx = "xmean: {}\nymean: {}".format(xm,ym)
    plt.text(.3,0.1+i*0.25,tx, color=color, transform=plt.gca().transAxes)
    plt.gca().axis("off")

g.map_upper(text)
plt.show()