Skip to content

Commit

Permalink
Show number of YoY histogram points when detailed=True (#324)
Browse files Browse the repository at this point in the history
* include number of points in figure text

* test

* changelog

* rerun notebooks

* Revert "rerun notebooks" (wrong branch...)

This reverts commit e4f6532.
  • Loading branch information
kandersolar authored May 18, 2022
1 parent f97a870 commit 827361f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
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

0 comments on commit 827361f

Please sign in to comment.