Skip to content

scatterplot without ticks doesn't print labels #3530

Description

@JanPalasek

Hello, I found a bug (or at least a very strange behavior) in sns.scatterplot.

Code:

import matplotlib.pyplot as plt
import seaborn as sns

dataset = sns.load_dataset("titanic")

d = {
  'xtick.top': False,
 'xtick.bottom': False,
 'xtick.labeltop': False,
 'xtick.labelbottom': False,
 'ytick.right': False,
 'ytick.left': False,
 'ytick.labelright': False,
 'ytick.labelleft': False
}
sns.set_theme(style="dark", rc=d)

ax = sns.scatterplot(dataset, x="age", y="fare")
ax.set(xlabel="Age", ylabel="Fare")
plt.show()

image

The plot hides xlabel and ylabel, even though it should be visible according to matplotlib rc settings.

The problem is here:

Module: seaborn._base, lines: 1199-1200
Code:

x_visible = any(t.get_visible() for t in ax.get_xticklabels())
ax.set_xlabel(self.variables.get("x", default_x), visible=x_visible)

Since I hide tick labels in matplotlib rc, x_visible variable is evaluated as False and the xlabel is hidden. However this is not what I want. I want a super clean plot with no ticks but still a label.

Temporary solution: manually overwrite visible when setting the xlabel and ylabel.

import matplotlib.pyplot as plt
import seaborn as sns

dataset = sns.load_dataset("titanic")

d = {
  'xtick.top': False,
 'xtick.bottom': False,
 'xtick.labeltop': False,
 'xtick.labelbottom': False,
 'ytick.right': False,
 'ytick.left': False,
 'ytick.labelright': False,
 'ytick.labelleft': False
}
sns.set_theme(style="dark", rc=d)

ax = sns.scatterplot(dataset, x="age", y="fare")
ax.set_xlabel(xlabel="Age", visible=True)
ax.set_ylabel(ylabel="Fare", visible=True)
plt.show()

image

Is the "visibility logic" still needed? Or can we remove it and just use matplotlib rc settings for this?

Versions:

  • seaborn==0.13.0
  • matplotlib==3.8.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions