-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: fix hardcoded scatter marker size issue #54204 #54304
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
Changes from all commits
8e91fea
fba8992
ad67170
5c3b676
d02538e
1e20c1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -605,7 +605,7 @@ Plotting | |
^^^^^^^^ | ||
- Bug in :meth:`Series.plot` when invoked with ``color=None`` (:issue:`51953`) | ||
- Fixed UserWarning in :meth:`DataFrame.plot.scatter` when invoked with ``c="b"`` (:issue:`53908`) | ||
- | ||
- Fixed bug in :meth:`DataFrame.plot.scatter` wherein marker size was previously hardcoded to a default value (:issue:`54204`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be a note in the deprecation section now |
||
|
||
Groupby/resample/rolling | ||
^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1199,9 +1199,18 @@ def _kind(self) -> Literal["scatter"]: | |||||
|
||||||
def __init__(self, data, x, y, s=None, c=None, **kwargs) -> None: | ||||||
if s is None: | ||||||
# hide the matplotlib default for size, in case we want to change | ||||||
# the handling of this argument later | ||||||
s = 20 | ||||||
# The default size of the elements in a scatter plot | ||||||
# is now based on the rcParam ``lines.markersize``. | ||||||
# This means that if rcParams are temporarily changed, | ||||||
# the marker size changes as well according to mpl.rc_context(). | ||||||
warnings.warn( | ||||||
"""The default of s=20 is deprecated and | ||||||
has changed to mpl.rcParams['lines.markersize']. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
Specify `s` to suppress this warning""", | ||||||
DeprecationWarning, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
stacklevel=find_stack_level(), | ||||||
) | ||||||
s = mpl.rcParams["lines.markersize"] ** 2.0 | ||||||
elif is_hashable(s) and s in data.columns: | ||||||
s = data[s] | ||||||
super().__init__(data, x, y, s=s, **kwargs) | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -662,3 +662,35 @@ def test_bar_plt_xaxis_intervalrange(self): | |
(a.get_text() == b.get_text()) | ||
for a, b in zip(s.plot.bar().get_xticklabels(), expected) | ||
) | ||
|
||
@pytest.mark.filterwarnings("default") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
def test_change_scatter_markersize_rcparams(self): | ||
# GH 54204 | ||
# Ensure proper use of lines.markersize to style pandas scatter | ||
# plots like matplotlib does. | ||
# Will raise deprecation warnings. | ||
df = DataFrame(data={"x": [1, 2, 3], "y": [1, 2, 3]}) | ||
|
||
pandas_default = df.plot.scatter( | ||
x="x", y="y", title="pandas scatter, default rc marker size" | ||
) | ||
|
||
mpl_default = mpl.pyplot.scatter(df["x"], df["y"]) | ||
|
||
# verify that pandas and matplotlib scatter | ||
# default marker size are the same (s = 6^2 = 36) | ||
assert ( | ||
pandas_default.collections[0].get_sizes()[0] == mpl_default.get_sizes()[0] | ||
) | ||
|
||
with mpl.rc_context({"lines.markersize": 10}): | ||
pandas_changed = df.plot.scatter( | ||
x="x", y="y", title="pandas scatter, changed rc marker size" | ||
) | ||
mpl_changed = mpl.pyplot.scatter(df["x"], df["y"]) | ||
|
||
# verify that pandas and matplotlib scatter | ||
# changed marker size are the same (s = 10^2 = 100) | ||
assert ( | ||
pandas_changed.collections[0].get_sizes()[0] == mpl_changed.get_sizes()[0] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add an
:okwarning:
below the ipython directive instead of this