Skip to content

Commit

Permalink
Merge branch 'develop' into issue-2098-SPMe-SR
Browse files Browse the repository at this point in the history
  • Loading branch information
brosaplanella committed Jul 27, 2022
2 parents 535bd14 + 9856785 commit 854b66c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/url_checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: URLs-checker
uses: urlstechie/urlchecker-action@master
uses: urlstechie/urlchecker-action@0.0.31
with:
# A comma-separated list of file types to cover in the URL checks
file_types: .rst,.md,.py,.ipynb
Expand All @@ -28,7 +28,7 @@ jobs:
retry_count: 5

# A comma separated patterns to exclude during URL checks
exclude_patterns: https://www.datacamp.com/community/tutorials/fuzzy-string-python,http://127.0.0.1,https://github.com/pybamm-team/PyBaMM/tree/v
exclude_patterns: https://www.datacamp.com/community/tutorials/fuzzy-string-python,http://127.0.0.1,https://github.com/pybamm-team/PyBaMM/tree/v,https::/doi.org,https::/www.sciencedirect.com

# A comma separated list of file patterns (direct paths work as well) to exclude
exclude_files: CHANGELOG.md
Expand Down
35 changes: 19 additions & 16 deletions pybamm/plotting/plot_voltage_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,51 +30,54 @@ def plot_voltage_components(
kwargs_fill = {"alpha": 0.6, **kwargs_fill}

if ax is not None:
fig = None
testing = True
else:
_, ax = plt.subplots()
fig, ax = plt.subplots()

overpotentials = [
"X-averaged battery reaction overpotential [V]",
"X-averaged battery concentration overpotential [V]",
"X-averaged battery electrolyte ohmic losses [V]",
"X-averaged battery solid phase ohmic losses [V]",
]
labels = [
"Reaction overpotential",
"Concentration overpotential",
"Ohmic electrolyte overpotential",
"Ohmic electrode overpotential",
]

# Plot
# Initialise
time = solution["Time [h]"].entries
initial_ocv = solution["X-averaged battery open circuit voltage [V]"](0)
ocv = solution["X-averaged battery open circuit voltage [V]"].entries
ax.fill_between(time, ocv, initial_ocv, **kwargs_fill)
ax.fill_between(time, ocv, initial_ocv, **kwargs_fill, label="Open-circuit voltage")
top = ocv
# Plot components
for overpotential in overpotentials:
for overpotential, label in zip(overpotentials, labels):
bottom = top + solution[overpotential].entries
ax.fill_between(time, bottom, top, **kwargs_fill)
ax.fill_between(time, bottom, top, **kwargs_fill, label=label)
top = bottom

V = solution["Battery voltage [V]"].entries
ax.plot(time, V, "k--")
ax.plot(time, V, "k--", label="Voltage")

if show_legend:
labels = [
"Open-circuit voltage",
"Reaction overpotential",
"Concentration overpotential",
"Ohmic electrolyte overpotential",
"Ohmic electrode overpotential",
"Voltage",
]
leg = ax.legend(labels, loc="lower left", frameon=True)
leg = ax.legend(loc="lower left", frameon=True)
leg.get_frame().set_edgecolor("k")

# Labels
ax.set_xlim([time[0], time[-1]])
ax.set_xlabel("Time [h]")

y_min, y_max = 0.98 * np.nanmin(V), 1.02 * np.nanmax(initial_ocv)
y_min, y_max = 0.98 * min(np.nanmin(V), np.nanmin(ocv)), 1.02 * (
max(np.nanmax(V), np.nanmax(ocv))
)
ax.set_ylim([y_min, y_max])

if not testing: # pragma: no cover
plt.show()

return ax
return fig, ax
4 changes: 2 additions & 2 deletions tests/unit/test_plotting/test_plot_voltage_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ def test_plot(self):
model = pybamm.lithium_ion.SPM()
sim = pybamm.Simulation(model)
sol = sim.solve([0, 3600])
ax = pybamm.plot_voltage_components(sol, show_legend=True, testing=True)
_, ax = pybamm.plot_voltage_components(sol, show_legend=True, testing=True)
t, V = ax.get_lines()[0].get_data()
np.testing.assert_array_equal(t, sol["Time [h]"].data)
np.testing.assert_array_equal(V, sol["Battery voltage [V]"].data)

_, ax = plt.subplots()
ax_out = pybamm.plot_voltage_components(sol, ax=ax, show_legend=True)
_, ax_out = pybamm.plot_voltage_components(sol, ax=ax, show_legend=True)
self.assertEqual(ax_out, ax)


Expand Down

0 comments on commit 854b66c

Please sign in to comment.