-
Notifications
You must be signed in to change notification settings - Fork 10
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
WIP: Change how the colorbar axis works #70
base: master
Are you sure you want to change the base?
Conversation
@@ -2,6 +2,7 @@ module UnitfulRecipes | |||
|
|||
using RecipesBase | |||
using Unitful: Quantity, unit, ustrip, Unitful, dimension, Units | |||
using Infiltrator |
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.
Only for development purposes
get!(attr, axislabel, label) | ||
end | ||
|
||
u = fixlabel!(attr, axisletter, unit(first(x))) |
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.
Much of this code needed to be repeated for the c
axis, so I factored it out.
# Fix the attributes: labels, lims, ticks, marker/line stuff, etc. | ||
append_unit_if_needed!(attr, axislabel, u) | ||
ustripattribute!(attr, axislims, u) | ||
ustripattribute!(attr, axisticks, u) | ||
ustripattribute!(attr, err, u) | ||
fixmarkercolor!(attr) | ||
fixcolors!(attr) |
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.
Need to run a single pass over all three color arguments, to combine into one axis.
end | ||
getlabel(attr, sp, axisname, labelname) = attr[:plot_object][sp][axisname][labelname] | ||
getlabel(attr, sp, axisname::Nothing, labelname) = attr[:plot_object][sp][labelname] |
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.
I think it's a limitation in Plots
that it's attr[:plot_object][sp][:colorbar_title]
rather than attr[:plot_object][sp][:caxis][:guide]
, but it is what it is.
ustripattribute!(plotattributes, :clims, u) | ||
z = fixaxis!(plotattributes, z, :z) | ||
append_unit_if_needed!(plotattributes, :colorbar_title, u) | ||
x, y, z |
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.
I don't think we need this recipe if x
, y
and z
are correctly identified as type targets for themselves.
Testing: using UnitfulRecipes
using Test
using Plots
using Unitful
#plotlyjs()
#gr()
pyplot()
default(; label=nothing)
x = randn(5)u"m"
t = randn(5)u"s"
T = randn(5)u"K"
E = 100 * randn(5)u"J"
pl1 = plot(x, t; marker_z=T, st=:scatter, xguide="x", yguide="t", colorbartitle="T")
pl2 = plot(x, t; line_z=T, st=:line, xguide="x", yguide="t", colorbartitle="T")
pl3 = plot(x, t; line_z=T, st=:line)
#plot!(pl3, x, t; marker_z=E, st=:scatter, colorbartitle="T or E?") # Rightfully fails
plot!(pl3, x, t; marker_z=T, st=:scatter, xguide="x", yguide="t", colorbartitle="T")
gaussian(x, y, x0, y0, wx, wy) = exp(-((x - x0)^2 / wx^2 + (y - y0)^2 / wy^2))
x = (-2:0.1:2)u"mm";
y = (-2:0.1:2)u"mm";
z = 1u"W/m^2" * gaussian.(x', y, 0u"mm", 0u"mm", 0.5u"mm", 1u"mm");
c = 300u"K" .+ 4u"K/mm" .* (x' .+ y);
println(size(c))
pl4 = plot(
x, y, z; fill_z=c, st=:surface, xguide="x", yguide="y", zguide="I", colorbar_title="T"
)
pl5 = plot(x, y, z; fill_z=c, st=:surface)
plot!(
pl5,
randn(5)u"mm",
randn(5)u"mm",
fill(1.5u"W/m^2", length(x));
xguide="x",
yguide="y",
zguide="I",
colorbar_title="T",
st=:line,
line_z=150u"K" .+ 20 * randn(size(x))u"K",
)
savefig.([pl1, pl2, pl3, pl4, pl5], ["pl1.png", "pl2.png", "pl3.png", "pl4.png", "pl5.png"])
#plot(pl1, pl2, pl3, pl4, pl5) To me, this PR can do what you want it to do. But it feels slightly unpolished: in If there are no complaints I'll just write tests and docs. |
Oh no, there are some regressions when running tests. I'll look at it. |
Issue #68
Tries to unify how we treat the axes and axis labels, and apply that to the
c
axis.In this state, it fails when applying a
plot!
call withline_z
ormarker_z
on top of one withfill_z
. And it kind of weirds out with implicitfill_z
(likeplot(x, y, z; st=:surface)
). But it correctly saves and checkscbar
units for lines and markers, as well as for onlyfill_z
.