Skip to content

matplotlib x axis labels dissapear in scatterplot #2353

Closed
@Kornel

Description

@Kornel

Please take look at http://stackoverflow.com/questions/43121584/matplotlib-scatterplot-x-axis-labels or https://github.com/Kornel/scatterplot-matplotlib/blob/master/Scatter%20plot%20x%20axis%20labels.ipynb

When I create a scatter plot with the colours specified using c="C" the x axis labels disappear.

import pandas as pd
%matplotlib inline
import matplotlib.pyplot as plt
%config InlineBackend.figure_format = 'retina'

test_df = pd.DataFrame({
        "X": [1, 2, 3, 4],
        "Y": [5, 4, 2, 1],
        "C": [1, 2, 3, 4]
    })

# This shows the x axis labels just fine
test_df.plot(kind="scatter", x="X", y="Y");

# This does not
test_df.plot(kind="scatter", x="X", y="Y", c="C");

The solution is to provide the axes explicitly:

fig, ax = plt.subplots()
test_df.plot(kind="scatter", x="X", y="Y", s=50, c="C", cmap="plasma", ax=ax);

This looks like a jupyter issue since calling this from "regular" python with savefig does not yield this problem.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions