Skip to content

Fix Scatter plot datetime and Axis #12949

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

Closed
wants to merge 6 commits into from
Closed
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
4 changes: 4 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3017,6 +3017,10 @@ def _get_numeric_data(self):
def _get_bool_data(self):
return self._constructor(self._data.get_bool_data()).__finalize__(self)

def _get_datetime_data(self):
return self._constructor(
self._data.get_datetime_data()).__finalize__(self)

# ----------------------------------------------------------------------
# Internal Interface Methods

Expand Down
10 changes: 10 additions & 0 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3354,6 +3354,16 @@ def get_numeric_data(self, copy=False):
self._consolidate_inplace()
return self.combine([b for b in self.blocks if b.is_numeric], copy)

def get_datetime_data(self, copy=False):
"""
Parameters
----------
copy : boolean, default False
Whether to copy the blocks
"""
self._consolidate_inplace()
return self.combine([b for b in self.blocks if b.is_datetime], copy)

def combine(self, blocks, copy=True):
""" return a new manager with the blocks """
if len(blocks) == 0:
Expand Down
32 changes: 30 additions & 2 deletions pandas/tools/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1579,8 +1579,11 @@ class PlanePlot(MPLPlot):

_layout_type = 'single'

def __init__(self, data, x, y, **kwargs):
MPLPlot.__init__(self, data, **kwargs)
def __init__(self, data, x, y, sharex=False, **kwargs):
if sharex is None:
Copy link
Member

Choose a reason for hiding this comment

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

To apply the same fix to hexbin, pls move the logic to PlanePlot. And I think sharex should be always False because we don't support scatter subplots ATM?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sinhrks This is in PlanePlot

# Fix x axis color bar problems
sharex = False
Copy link
Member

Choose a reason for hiding this comment

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

This sharex fix, is this independent from the datetime fix?
If so, can you make a separate PR for it?

MPLPlot.__init__(self, data, sharex=sharex, **kwargs)
if x is None or y is None:
raise ValueError(self._kind + ' requires and x and y column')
if is_integer(x) and not self.data.columns.holds_integer():
Expand Down Expand Up @@ -1613,6 +1616,31 @@ def __init__(self, data, x, y, s=None, c=None, **kwargs):
c = self.data.columns[c]
self.c = c

def _compute_plot_data(self):
data = self.data

if isinstance(data, Series):
label = self.label
if label is None and data.name is None:
label = 'None'
data = data.to_frame(name=label)

numeric_dt__data = data._convert(datetime=True)._get_numeric_data()
time_data = data._convert(datetime=True)._get_datetime_data()
numeric_dt__data = numeric_dt__data.join(time_data)

try:
is_empty = numeric_dt__data.empty
except AttributeError:
is_empty = not len(numeric_dt__data)

# no empty frames or series allowed
if is_empty:
raise TypeError('Empty {0!r}: no numeric data to '
'plot'.format(numeric_dt__data.__class__.__name__))

self.data = numeric_dt__data

def _make_plot(self):
x, y, c, data = self.x, self.y, self.c, self.data
ax = self.axes[0]
Expand Down