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

Replace PyPlot with Plots to remove unnecessary Python dep #84

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

hdrake
Copy link
Collaborator

@hdrake hdrake commented Feb 5, 2022

No description provided.

@hdrake hdrake changed the title Use plotsjl Replace PyPlot with Plots to remove unnecessary Python dep Feb 5, 2022
@hdrake
Copy link
Collaborator Author

hdrake commented Feb 5, 2022

Still need to re-implement the default_configuration.jl and one-two_dimensional_optimization.jl examples and probably purge PyPlot calls in other places in the source code.

@hdrake
Copy link
Collaborator Author

hdrake commented Feb 5, 2022

I've gotten the figures with Plots.jl to look fairly similar to the PyPlot ones published in the ClimateMARGO paper, but their quality is still somewhat limited by Plots.jl capabilities (e.g. unclear why the lines in the legend are so long, or how to fix that).

download-1

@hdrake
Copy link
Collaborator Author

hdrake commented Feb 5, 2022

@fonsp, I think I've now removed all traces of Python, PyCall, and PyPlot from the entire package!

@hdrake hdrake requested a review from fonsp February 5, 2022 21:33
@hdrake hdrake marked this pull request as ready for review February 5, 2022 21:33
using LaTeXStrings
using Plots.Measures

default(label="", grid=true, gridalpha=0.15)
Copy link
Member

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")
Copy link
Member

@fonsp fonsp Feb 9, 2022

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()
Copy link
Member

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)
Copy link
Member

@fonsp fonsp Feb 9, 2022

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
Copy link
Member

@fonsp fonsp Feb 9, 2022

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 🐛

Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants