Skip to content
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

Show number of YoY histogram points when detailed=True #324

Merged
merged 6 commits into from
May 18, 2022
Merged
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
6 changes: 6 additions & 0 deletions docs/sphinx/source/changelog/pending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
Pending
************************

Enhancements
------------
* Specifying ``detailed=True`` in :py:func:`rdtools.plotting.degradation_summary_plots`
now shows the number of year-on-year slopes in addition to color coding points
(:issue:`298`, :pull:`324`)

Testing
-------
* Added a CI notebook check (:pull:`270`)
Expand Down
15 changes: 11 additions & 4 deletions rdtools/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ def degradation_summary_plots(yoy_rd, yoy_ci, yoy_info, normalized_yield,
scatter_alpha : float, default 0.5
Transparency of the scatter plot
detailed : bool, optional
Color code points by the number of times they get used in calculating
Rd slopes. Default color: 2 times (as a start and endpoint). Green:
1 time. Red: 0 times.
Include extra information in the returned figure:

* Color code points by the number of times they get used in calculating
Rd slopes. Default color: 2 times (as a start and endpoint). Green:
1 time. Red: 0 times.
* The number of year-on-year slopes contributing to the histogram.

Note
----
Expand Down Expand Up @@ -96,7 +99,11 @@ def degradation_summary_plots(yoy_rd, yoy_ci, yoy_info, normalized_yield,
'confidence interval: \n'
'%.2f to %.2f %%/yr' % (yoy_rd, yoy_ci[0], yoy_ci[1])
)
ax2.annotate(label, xy=(0.5, 0.7), xycoords='axes fraction',
if detailed:
n = yoy_values.notnull().sum()
label += '\n' + f'n = {n}'

ax2.annotate(label, xy=(0.5, 0.6), xycoords='axes fraction',
bbox=dict(facecolor='white', edgecolor=None, alpha=0))
ax2.set_xlabel('Annual degradation (%)')

Expand Down
8 changes: 8 additions & 0 deletions rdtools/test/plotting_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
availability_summary_plots
)
import matplotlib.pyplot as plt
import matplotlib
import plotly
import pytest
import re

from conftest import assert_isinstance

Expand Down Expand Up @@ -81,6 +83,12 @@ def test_degradation_summary_plots_kwargs(degradation_info):
result = degradation_summary_plots(yoy_rd, yoy_ci, yoy_info, power,
**kwargs)
assert_isinstance(result, plt.Figure)

# ensure the number of points is included when detailed=True
ax = result.axes[1]
labels = [c for c in ax.get_children() if isinstance(c, matplotlib.text.Annotation)]
text = labels[0].get_text()
assert re.search(r'n = \d', text)
plt.close('all')


Expand Down