more than one colorbar
This commit is contained in:
parent
567d3688e8
commit
c9c4de37e6
@ -1,4 +1,5 @@
|
|||||||
using Contour: Contour
|
using Contour: Contour
|
||||||
|
using StatsBase: Histogram, fit
|
||||||
# PGFPlotsX.print_tex(io::IO, data::ColorGradient) = write(io, pgfx_colormap(data))
|
# PGFPlotsX.print_tex(io::IO, data::ColorGradient) = write(io, pgfx_colormap(data))
|
||||||
Base.@kwdef mutable struct PGFPlotsXPlot
|
Base.@kwdef mutable struct PGFPlotsXPlot
|
||||||
is_created::Bool = false
|
is_created::Bool = false
|
||||||
@ -33,7 +34,6 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
pushed_colormap = false
|
|
||||||
for sp in plt.subplots
|
for sp in plt.subplots
|
||||||
bb = bbox(sp)
|
bb = bbox(sp)
|
||||||
cstr = plot_color(sp[:background_color_legend])
|
cstr = plot_color(sp[:background_color_legend])
|
||||||
@ -65,37 +65,17 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
|||||||
pgfx_axis!(axis_opt, sp, letter)
|
pgfx_axis!(axis_opt, sp, letter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# Search series for any gradient. In case one series uses a gradient set
|
if hascolorbar(sp)
|
||||||
# the colorbar and colomap.
|
|
||||||
# The reasoning behind doing this on the axis level is that pgfplots
|
|
||||||
# colorbar seems to only works on axis level and needs the proper colormap for
|
|
||||||
# correctly displaying it.
|
|
||||||
# It's also possible to assign the colormap to the series itself but
|
|
||||||
# then the colormap needs to be added twice, once for the axis and once for the
|
|
||||||
# series.
|
|
||||||
# As it is likely that all series within the same axis use the same
|
|
||||||
# colormap this should not cause any problem.
|
|
||||||
for series in series_list(sp)
|
|
||||||
for col in (:markercolor, :fillcolor, :linecolor)
|
|
||||||
if typeof(series.plotattributes[col]) == ColorGradient
|
|
||||||
if !pushed_colormap
|
|
||||||
PGFPlotsX.push_preamble!(pgfx_plot.the_plot, """\\pgfplotsset{
|
PGFPlotsX.push_preamble!(pgfx_plot.the_plot, """\\pgfplotsset{
|
||||||
colormap={plots}{$(pgfx_colormap(series.plotattributes[col]))},
|
colormap={plots$(sp.attr[:subplot_index])}{$(pgfx_colormap(series.plotattributes[col]))},
|
||||||
}""")
|
}""")
|
||||||
pushed_colormap = true
|
pushed_colormap = true
|
||||||
push!(axis_opt,
|
push!(axis_opt,
|
||||||
"colorbar" => nothing,
|
"colorbar" => nothing,
|
||||||
"colormap name" => "plots",
|
"colormap name" => "plots$(sp.attr[:subplot_index])",
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
# goto is needed to break out of col and series for
|
|
||||||
@goto colorbar_end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@label colorbar_end
|
|
||||||
|
|
||||||
push!(axis_opt, "colorbar style" => PGFPlotsX.Options(
|
push!(axis_opt, "colorbar style" => PGFPlotsX.Options(
|
||||||
"title" => sp[:colorbar_title],
|
"title" => sp[:colorbar_title],
|
||||||
)
|
)
|
||||||
@ -181,6 +161,8 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
|||||||
PGFPlotsX.Table(Contour.contours(args..., opt[:levels]))
|
PGFPlotsX.Table(Contour.contours(args..., opt[:levels]))
|
||||||
)
|
)
|
||||||
push!(axis, surface_plot)
|
push!(axis, surface_plot)
|
||||||
|
elseif st == :histogram2d
|
||||||
|
hist_
|
||||||
else
|
else
|
||||||
# treat segments
|
# treat segments
|
||||||
segments = iter_segments(series)
|
segments = iter_segments(series)
|
||||||
|
|||||||
@ -90,4 +90,16 @@ end
|
|||||||
plot(p1, p2)
|
plot(p1, p2)
|
||||||
# TODO: filled contours
|
# TODO: filled contours
|
||||||
end # testset
|
end # testset
|
||||||
|
@testset "Varying colors" begin
|
||||||
|
t = range(0, stop=1, length=100)
|
||||||
|
θ = (6π) .* t
|
||||||
|
x = t .* cos.(θ)
|
||||||
|
y = t .* sin.(θ)
|
||||||
|
p1 = plot(x, y, line_z=t, linewidth=3, legend=false)
|
||||||
|
p2 = scatter(x, y, marker_z=((x, y)->begin
|
||||||
|
x + y
|
||||||
|
end), color=:bluesreds, legend=false)
|
||||||
|
plot(p1, p2)
|
||||||
|
# TODO: handle gradients as color
|
||||||
|
end # testset
|
||||||
end # testset
|
end # testset
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user