Skip to content

BUG: Scatterplot x-axis label disappears with colorscale when using matplotlib backend #36064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
discdiver opened this issue Sep 2, 2020 · 11 comments
Labels

Comments

@discdiver
Copy link

discdiver commented Sep 2, 2020


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

# Your code here
import matplotlib.cm as cm
import pandas as pd
import numpy as np

X = np.random.rand(10,3)

df = pd.DataFrame(X,columns=['t','hlReference', 'STEP_STRENGTH'])

df.plot.scatter(
    x='t', 
    y='hlReference', 
    c='STEP_STRENGTH', 
    cmap=cm.autumn,)

Problem description

X-axis label disappears when you add a colorscale to a scatterplot when using matplotlib backend.

UPDATE confirmed this bug occurs in Jupyter and when files are written out

Example taken from this SO question that also shows the two workarounds.

Workaround 1: Get an ax object and pass ax=ax.
Workaround 2: Pass sharex=False

A previous solution to the problem is discussed in closed issue #10611, but it appears that stopped working in 0.24.0.

Expected Output

Show the x-axis label.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : d9fff27
python : 3.7.6.final.0
python-bits : 64
OS : Darwin
OS-release : 18.7.0
Version : Darwin Kernel Version 18.7.0: Thu Jun 18 20:50:10 PDT 2020; root:xnu-4903.278.43~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.1.0
numpy : 1.18.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.2
setuptools : 49.6.0.post20200814
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.5.1
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.16.1
pandas_datareader: None
bs4 : 4.9.1
bottleneck : 1.3.2
fsspec : 0.7.4
fastparquet : None
gcsfs : None
matplotlib : 3.2.2
numexpr : 2.7.1
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 0.16.0
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : None
tabulate : 0.8.7
xarray : None
xlrd : None
xlwt : None
numba : 0.50.0

@discdiver discdiver added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 2, 2020
@TomAugspurger
Copy link
Contributor

Is this limited to the inline notebook backend?

Can you figure out which version / commit introduced the regression?

@TomAugspurger TomAugspurger added Visualization plotting and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 4, 2020
@discdiver
Copy link
Author

discdiver commented Sep 4, 2020 via email

@discdiver
Copy link
Author

I have tested with file output @TomAugspurger and can confirm that the bug is present there as well.

import matplotlib.cm as cm
import pandas as pd
import numpy as np

X = np.random.rand(10,3)

df = pd.DataFrame(X,columns=['t','hlReference', 'STEP_STRENGTH'])

fig = df.plot(
    kind='scatter',
    x='t', 
    y='hlReference', 
    c='STEP_STRENGTH', 
    cmap=cm.autumn,
).get_figure()

fig.savefig('test')

@stragu
Copy link
Contributor

stragu commented Dec 11, 2020

#10611 definitely seems to be back.

Here is a minimal example:

import pandas as pd
df = pd.DataFrame([1,2,3])
# has x labels:
df.plot(kind = "scatter", x = 0, y = 0)
# does not have x labels:
df.plot(kind = "scatter", x = 0, y = 0, c = 0)

image

image

That was shown in the Spyder plot pane, but I get the same result when saving to file:

fig = df.plot(kind = "scatter", x = 0, y = 0, c = 0).get_figure()
fig.savefig('test')

Currently using pandas 1.1.5 (and matplotlib 3.3.3)

@igurin-invn
Copy link

I see the same behavior on pandas 1.3.0. Can we at least get a milestone assignment?

@jreback
Copy link
Contributor

jreback commented Aug 3, 2021

@igurin-invn you or anyone in the community can submit a PR at anytime

pandas core can barely keep up with reviews - issues are assigned a milestone when their is a PR

@jreback jreback added this to the Contributions Welcome milestone Aug 3, 2021
@igurin-invn
Copy link

Not an expert, but trying to investigate. Looks like the axis and tick labels are really gone.

ax = df.plot.scatter(x='A', y='B', c='C', cmap='viridis')

image

ax = df.plot.scatter(x='A', y='B', c='C', cmap='viridis')
ax.set_position([0.125, 0.3, 0.6, 0.6])

image

But ax.get_xlabel() gives a non-blank value.

@kwinkunks
Copy link

This seems to be fixed in pandas 1.3.2 (with matplotlib 3.4.3, Python 3.9), but I can't find a reference to #36064 anywhere so I don't know what fixed it.

>>> import pandas as pd
>>> df = pd.DataFrame([1,2,3])
>>> df.plot(kind='scatter', x=0, y=0, c=0)

image

I really dislike the default colourmap because it results in invisible points, but the x-axis label is there at least.

If someone can confirm then I think this issue can be closed.

@igurin-invn
Copy link

I upgraded to the same versions that you have, but it doesn't work for me.

image

@al-becker
Copy link

As a workaround setting sharex=False might help.

@barthoekstra
Copy link

sharex=False fixes it for me, but this is still an issue on pandas 1.3.4 and matplotlib 3.5.0 with Python 3.9.7.

@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants