Skip to content

Commit

Permalink
Merge pull request #23 from py1sl/minor-fixes---plotly-no-std-error
Browse files Browse the repository at this point in the history
fixed plotly with no error, fixed matplotlib legends
  • Loading branch information
shimwell committed Mar 3, 2022
2 parents dc3d920 + fcd0da3 commit d49e7cd
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions spectrum_plotter/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ def plot_spectrum_from_values(
plotting_package=plotting_package,
figure=figure,
)
# add legend to matplotlib after label names have been set
if legend and plotting_package == "matplotlib":
figure.legend()

save_plot(plotting_package=plotting_package, filename=filename, figure=figure)

Expand Down Expand Up @@ -203,9 +206,6 @@ def add_axis_title_labels(

plt.title(title)

if legend:
plt.legend()

return plt

elif plotting_package == "plotly":
Expand Down Expand Up @@ -311,30 +311,32 @@ def add_spectra_to_plot(
# options are 'linear', 'spline', 'hv', 'vh', 'hvh', 'vhv'
shape = "hv"

# adds a line for the upper stanadard deviation bound
figure.add_trace(
go.Scatter(
mode="lines",
x=x,
y=y + y_err,
line=dict(shape=shape, width=0),
if len(spectra) == 3:
# adds a line for the upper stanadard deviation bound
figure.add_trace(
go.Scatter(
mode="lines",
x=x,
y=y + y_err,
name="std. dev. upper",
line=dict(shape=shape, width=0),
)
)
)

# adds a line for the lower stanadard deviation bound
figure.add_trace(
go.Scatter(
mode="lines",
x=x,
# todo process std dev correction
y=y - y_err,
name="std. dev.",
# options are 'none', 'tozeroy', 'tozerox', 'tonexty', 'tonextx', 'toself', 'tonext'
fill="tonextx",
fillcolor=f"rgba{(0.2,0.2,0.2, 0.1)}",
line=dict(shape=shape, width=0),
# adds a line for the lower stanadard deviation bound
figure.add_trace(
go.Scatter(
mode="lines",
x=x,
# todo process std dev correction
y=y - y_err,
name="std. dev. lower",
# options are 'none', 'tozeroy', 'tozerox', 'tonexty', 'tonextx', 'toself', 'tonext'
fill="tonextx",
fillcolor=f"rgba{(0.2,0.2,0.2, 0.1)}",
line=dict(shape=shape, width=0),
)
)
)

# adds a line for the tally result
figure.add_trace(
Expand Down

0 comments on commit d49e7cd

Please sign in to comment.