Skip to content

misplaced scatter/hexbin subplot colorbars #21728

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

Merged
merged 4 commits into from
Jul 5, 2018

Conversation

javadnoorb
Copy link
Contributor

@javadnoorb javadnoorb commented Jul 4, 2018

NOTE: I have tested the following in Jupyter lab.

When I run:

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
random_array = np.random.random((1000,3))
df = pd.DataFrame(random_array,columns=['A label','B label','C label'])

fig, axes = plt.subplots(1, 2)
df.plot.scatter('A label','B label', c='C label', ax=axes[0])
df.plot.scatter('A label','B label', c='C label', ax=axes[1])
plt.tight_layout()

I get:

image

This PR fixes the issue with colorbars. After the PR the output is:

image

This also fixes similar issue with hexbin plot. To explore different configurations try the following function:

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

def make_multiplots(numrows=2,numcols=2,sharey=True,sharex=True, is_scatter = True):
    fig, axes = plt.subplots(numrows, numcols, sharey=sharey, sharex=sharex )
    for i in range(axes.shape[0]):
        for j in range(axes.shape[1]):
            random_array = np.random.random((1000,3))
            df = pd.DataFrame(random_array,columns=['A label','B label','C label'])
            if is_scatter:
                df.plot.scatter('A label', 'B label', c='C label', ax=axes[i,j]);
            else:
                df.plot.hexbin('A label', 'B label', gridsize=20, ax=axes[i,j]);

make_multiplots(numrows=2,numcols=3,sharey=False, sharex=False, is_scatter=False)
plt.tight_layout()

image

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can u modify the test to catch this? (if possible / if not ok)

@@ -337,7 +337,7 @@ Plotting
^^^^^^^^

- Bug in :func:'DataFrame.plot.scatter' and :func:'DataFrame.plot.hexbin' caused x-axis label and ticklabels to disappear when colorbar was on in IPython inline backend (:issue:`10611` and :issue:`10678`)
-
- Bug in :func:'DataFrame.plot.scatter' and :func:'DataFrame.plot.hexbin' resulted in misplaced colorbars when subplot was used (related to :issue:`20455`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don’t need another entry, just add on to the previous one (just the number is ok)

@codecov
Copy link

codecov bot commented Jul 4, 2018

Codecov Report

Merging #21728 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #21728      +/-   ##
==========================================
+ Coverage   91.92%   91.93%   +<.01%     
==========================================
  Files         158      159       +1     
  Lines       49705    49719      +14     
==========================================
+ Hits        45693    45707      +14     
  Misses       4012     4012
Flag Coverage Δ
#multiple 90.3% <100%> (ø) ⬆️
#single 42.02% <0%> (+0.02%) ⬆️
Impacted Files Coverage Δ
pandas/plotting/_core.py 83.57% <100%> (ø) ⬆️
pandas/core/arrays/period.py 86.53% <0%> (-13.47%) ⬇️
pandas/core/arrays/datetimelike.py 94.38% <0%> (-0.14%) ⬇️
pandas/core/indexes/timedeltas.py 91.05% <0%> (-0.04%) ⬇️
pandas/core/indexes/datetimes.py 95.48% <0%> (-0.01%) ⬇️
pandas/core/generic.py 96.21% <0%> (-0.01%) ⬇️
pandas/core/arrays/timedelta.py 100% <0%> (ø) ⬆️
pandas/core/arrays/datetimes.py 100% <0%> (ø) ⬆️
pandas/_libs/tslibs/__init__.py 100% <0%> (ø)
pandas/core/indexes/datetimelike.py 96.98% <0%> (+0.11%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 62a0ebc...ad2b52a. Read the comment docs.

@jreback jreback added the Visualization plotting label Jul 4, 2018
@javadnoorb
Copy link
Contributor Author

Thanks @jreback. I included a test that checks if the distance between subplot parent axes is almost the same as the distance between colorbars.

I'm not sure what @pytest.mark.slow does. I assumed it's for skipping tests that are slow. Do I need it?

@jreback jreback added this to the 0.24.0 milestone Jul 5, 2018
@jreback jreback merged commit 3f7a385 into pandas-dev:master Jul 5, 2018
@jreback
Copy link
Contributor

jreback commented Jul 5, 2018

thanks @javadnoorb

@javadnoorb javadnoorb deleted the subplot-inline branch July 5, 2018 16:52
Sup3rGeo pushed a commit to Sup3rGeo/pandas that referenced this pull request Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

xlabel disappears in scatter plots with subplots and colorbar
2 participants