-
Notifications
You must be signed in to change notification settings - Fork 13
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
Replace PyPlot with Plots to remove unnecessary Python dep #84
base: main
Are you sure you want to change the base?
Conversation
These were testing with the default_optimization.jl core example.
Still need to re-implement the |
- Yticklabels on control deployment plots were not correctly displaying - Dollar sign not showing us with \$ in LaTeXStrings
@fonsp, I think I've now removed all traces of Python, PyCall, and PyPlot from the entire package! |
using LaTeXStrings | ||
using Plots.Measures | ||
|
||
default(label="", grid=true, gridalpha=0.15) |
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.
This line, and line 1 (gr()
) will also set the defaults for everything else the user wants to do outside of this package, which can be very confusing (running import ClimateMargo
would suddenly show grids on all plots).
Instead, we can have function to create a "base plot":
create_baseplot() = plot(; label="", grid=true, gridalpha=0.15)
...continued
xlabel("year") | ||
grid(true, alpha=0.3) | ||
return | ||
p = plot(title="net greenhouse gas emissions") |
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.
...continued
Which you can use here:
p = create_baseplot()
plot!(p, title="net greenhouse gas emissions")
ylim(ylims) | ||
return | ||
end | ||
gr() |
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.
This is already the default for Plots.jl, so it's better to remove it here, and let the user change it if they want to by adding gr()
in their notebook.
plot!(p, ylabel = L"effective CO$_{2e}$ emissions [ppm / yr]", xlabel="year") | ||
plot!(p, xticks = t(m)[1]:40.:2200.) | ||
plot!(p, legend=:bottomleft) | ||
return p | ||
end | ||
|
||
function plot_concentrations(m::ClimateModel) |
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.
You can change this into:
function plot_concentrations(m::ClimateModel; kwargs...)
continued...
plot!(p, ylabel=L"CO$_{2e}$ concentration [ppm]", xlabel="year") | ||
plot!(p, xlim=(t(m)[1],2200.), ylim=ylims, xticks=t(m)[1]:40.:2200.) | ||
plot!(p, legend=:topleft) | ||
return p |
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.
...continued
And here, you allow the user to override any setting that they want:
return plot!(p; kwargs...)
For example, this lets you do:
plot_concentrations(model; size=(100,100))
to create a tiny concentrations 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.
Same for the other plotting methods
No description provided.