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

时间:2017-05-16 14:12:39

标签: python matplotlib seaborn

在下图中,我想删除右上图中的x和y轴线,如何在不删除文本的情况下执行此操作?

The plot in question

我试过了:

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

但它不会这样做。

1 个答案:

答案 0 :(得分:2)

您可以使用

关闭轴
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()

enter image description here

相关问题