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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,7 @@ I/O
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' caused x-axis label and ticklabels to disappear when colorbar was on in IPython inline backend (:issue:`10611`, :issue:`10678`, and :issue:`20455`)
-

Groupby/Resample/Rolling
Expand Down
2 changes: 1 addition & 1 deletion pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ def _plot_colorbar(self, ax, **kwds):
# https://github.com/ipython/ipython/issues/11215

img = ax.collections[0]
cbar = self.fig.colorbar(img, **kwds)
cbar = self.fig.colorbar(img, ax=ax, **kwds)
points = ax.get_position().get_points()
cbar_points = cbar.ax.get_position().get_points()
cbar.ax.set_position([cbar_points[0, 0],
Expand Down
20 changes: 20 additions & 0 deletions pandas/tests/plotting/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,26 @@ def test_if_hexbin_xaxis_label_is_visible(self):
ax.xaxis.get_majorticklabels()])
assert ax.xaxis.get_label().get_visible()

@pytest.mark.slow
def test_if_scatterplot_colorbars_are_next_to_parent_axes(self):
import matplotlib.pyplot as plt
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()

points = np.array([ax.get_position().get_points()
for ax in fig.axes])
axes_x_coords = points[:, :, 0]
parent_distance = axes_x_coords[1, :] - axes_x_coords[0, :]
colorbar_distance = axes_x_coords[3, :] - axes_x_coords[2, :]
assert np.isclose(parent_distance,
colorbar_distance, atol=1e-7).all()

@pytest.mark.slow
def test_plot_scatter_with_categorical_data(self):
# GH 16199
Expand Down