-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Fix scatter norm keyword #45966
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
Fix scatter norm keyword #45966
Changes from 11 commits
5ee4bdd
742527e
c9cb9e2
54e60ee
082e3f9
9f5e363
4406906
a4b9b97
9ce0c55
0da0941
a15bd69
eedb617
0f32c4f
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 |
---|---|---|
|
@@ -787,6 +787,25 @@ def test_plot_scatter_with_s(self): | |
ax = df.plot.scatter(x="a", y="b", s="c") | ||
tm.assert_numpy_array_equal(df["c"].values, right=ax.collections[0].get_sizes()) | ||
|
||
def test_plot_scatter_with_norm(self): | ||
mroeschke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# added while fixing GH 45809 | ||
import matplotlib as mpl | ||
|
||
df = DataFrame(np.random.random((10, 3)) * 100, columns=["a", "b", "c"]) | ||
norm = mpl.colors.LogNorm() | ||
ax = df.plot.scatter(x="a", y="b", c="c", norm=norm) | ||
assert ax.collections[0].norm is norm | ||
|
||
def test_plot_scatter_without_norm(self): | ||
# added while fixing GH 45809 | ||
import matplotlib as mpl | ||
|
||
df = DataFrame(np.random.random((10, 3)) * 100, columns=["a", "b", "c"]) | ||
ax = df.plot.scatter(x="a", y="b", c="c") | ||
color_min_max = (df.c.min(), df.c.max()) | ||
default_norm = mpl.colors.Normalize(*color_min_max) | ||
assert all(df.c.apply(lambda x: ax.collections[0].norm(x) == default_norm(x))) | ||
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. Could this be done without apply? It will be easier to debug if this assertion doesn't go through necessary code paths. 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. What's the better approach? Just a loop? 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. Yeah the old check you had prior was good. The data doesn't have to be random as well if that helps shorten your loop and allows looping over less values 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. Ok, I'll revert to the previous check. I think looping over the values in the dataframe makes sense; it's replicating what's going on in the actual plot, and there's no real benefit to including values that are out of bounds - that's matplotlib normalize functionality. 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. Changes made |
||
|
||
@pytest.mark.slow | ||
def test_plot_bar(self): | ||
df = DataFrame( | ||
|
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.
I see this PR has now been merged, but I think this is supposed to be
`DataFrame.plot.scatter`
. Are the changelogs worth fixing?