more than one colorbar

This commit is contained in:
Simon Christ 2019-11-21 15:45:35 +01:00
parent 567d3688e8
commit c9c4de37e6
2 changed files with 24 additions and 30 deletions

View File

@ -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,36 +65,16 @@ 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. PGFPlotsX.push_preamble!(pgfx_plot.the_plot, """\\pgfplotsset{
# The reasoning behind doing this on the axis level is that pgfplots colormap={plots$(sp.attr[:subplot_index])}{$(pgfx_colormap(series.plotattributes[col]))},
# colorbar seems to only works on axis level and needs the proper colormap for }""")
# correctly displaying it. pushed_colormap = true
# It's also possible to assign the colormap to the series itself but push!(axis_opt,
# then the colormap needs to be added twice, once for the axis and once for the "colorbar" => nothing,
# series. "colormap name" => "plots$(sp.attr[:subplot_index])",
# 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{
colormap={plots}{$(pgfx_colormap(series.plotattributes[col]))},
}""")
pushed_colormap = true
push!(axis_opt,
"colorbar" => nothing,
"colormap name" => "plots",
)
end
# goto is needed to break out of col and series for
@goto colorbar_end
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)

View File

@ -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