Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ I/O
Plotting
^^^^^^^^

-
- BUG in :meth:`Series.plot` not able to plot boolean data (:issue:`23719`)
-

Groupby/resample/rolling
Expand Down
2 changes: 2 additions & 0 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,8 @@ class PlotAccessor(PandasObject):
mark_right : bool, default True
When using a secondary_y axis, automatically mark the column
labels with "(right)" in the legend
include_bool : bool, default is False
If True, boolean values can be plotted
`**kwds` : keywords
Options to pass to matplotlib plotting method
Expand Down
11 changes: 8 additions & 3 deletions pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def __init__(
colormap=None,
table=False,
layout=None,
include_bool=False,
**kwds
):

Expand Down Expand Up @@ -191,6 +192,7 @@ def __init__(
self.colormap = colormap

self.table = table
self.include_bool = include_bool

self.kwds = kwds

Expand Down Expand Up @@ -400,9 +402,12 @@ def _compute_plot_data(self):
# GH16953, _convert is needed as fallback, for ``Series``
# with ``dtype == object``
data = data._convert(datetime=True, timedelta=True)
numeric_data = data.select_dtypes(
include=[np.number, "datetime", "datetimetz", "timedelta"]
)
select_include_type = [np.number, "datetime", "datetimetz", "timedelta"]

# GH23719, allow plotting boolean
if self.include_bool is True:
select_include_type.append(np.bool_)
numeric_data = data.select_dtypes(include=select_include_type)

try:
is_empty = numeric_data.empty
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/plotting/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ def test_label(self):
ax.legend() # draw it
self._check_legend_labels(ax, labels=["LABEL"])

def test_boolean(self):
# GH 23719
s = Series([False, False, True])
_check_plot_works(s.plot, include_bool=True)

msg = "no numeric data to plot"
with pytest.raises(TypeError, match=msg):
_check_plot_works(s.plot)

def test_line_area_nan_series(self):
values = [1, 2, np.nan, 3]
s = Series(values)
Expand Down