-
-
Notifications
You must be signed in to change notification settings - Fork 417
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
Add circular histogram and KDE plot #1266
Changes from all commits
6dc14ca
f82a765
dab16c1
f811169
599825c
b1be37c
8f02d64
2f5b77d
ea8859f
e8db4dd
f41056f
680f36f
506048e
5793399
6020607
3c7670a
3c42a3a
5b0a0a4
8a99512
5bf3064
97cdaca
4fd0f5c
42aa26a
d97e1e0
b6e50f1
583079c
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 |
---|---|---|
|
@@ -29,6 +29,7 @@ def plot_dist( | |
contourf_kwargs, | ||
pcolormesh_kwargs, | ||
hist_kwargs, | ||
is_circular, | ||
ax, | ||
backend_kwargs, | ||
show, | ||
|
@@ -43,11 +44,16 @@ def plot_dist( | |
) | ||
backend_kwargs = None | ||
if ax is None: | ||
ax = plt.gca() | ||
ax = plt.gca(polar=is_circular) | ||
Comment on lines
46
to
+47
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. Is using 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. I think this is intended 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. Will 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. if present, 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. I believe this is considered a "best practice" with matplotlib, and a pattern they endorse. |
||
|
||
if kind == "hist": | ||
ax = _histplot_mpl_op( | ||
values=values, values2=values2, rotated=rotated, ax=ax, hist_kwargs=hist_kwargs | ||
values=values, | ||
values2=values2, | ||
rotated=rotated, | ||
ax=ax, | ||
hist_kwargs=hist_kwargs, | ||
is_circular=is_circular, | ||
) | ||
|
||
elif kind == "kde": | ||
|
@@ -77,6 +83,7 @@ def plot_dist( | |
ax=ax, | ||
backend="matplotlib", | ||
backend_kwargs=backend_kwargs, | ||
is_circular=is_circular, | ||
show=show, | ||
) | ||
|
||
|
@@ -86,20 +93,48 @@ def plot_dist( | |
return ax | ||
|
||
|
||
def _histplot_mpl_op(values, values2, rotated, ax, hist_kwargs): | ||
def _histplot_mpl_op(values, values2, rotated, ax, hist_kwargs, is_circular): | ||
"""Add a histogram for the data to the axes.""" | ||
bins = hist_kwargs.pop("bins", None) | ||
|
||
if is_circular == "degrees": | ||
if bins is None: | ||
bins = get_bins(values) | ||
values = np.deg2rad(values) | ||
bins = np.deg2rad(bins) | ||
|
||
elif is_circular: | ||
labels = [ | ||
r"0", | ||
r"π/4", | ||
r"π/2", | ||
r"3π/4", | ||
r"π", | ||
r"5π/4", | ||
r"3π/2", | ||
r"7π/4", | ||
] | ||
|
||
ax.set_xticklabels(labels) | ||
|
||
if values2 is not None: | ||
raise NotImplementedError("Insert hexbin plot here") | ||
|
||
bins = hist_kwargs.pop("bins") | ||
if bins is None: | ||
bins = get_bins(values) | ||
ax.hist(np.asarray(values).flatten(), bins=bins, **hist_kwargs) | ||
|
||
n, _, _ = ax.hist(np.asarray(values).flatten(), bins=bins, **hist_kwargs) | ||
|
||
if rotated: | ||
ax.set_yticks(bins[:-1]) | ||
else: | ||
elif not is_circular: | ||
ax.set_xticks(bins[:-1]) | ||
|
||
if is_circular: | ||
ax.set_ylim(0, 1.5 * n.max()) | ||
ax.set_yticklabels([]) | ||
|
||
if hist_kwargs.get("label") is not None: | ||
ax.legend() | ||
|
||
return ax |
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.
We are always showing a full circle plot?
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 think that's what everybody does (I know this is not a very good argument, haha)