integrate colorpalettes in pgfplotsx
This commit is contained in:
parent
becfa33ee8
commit
f1e7e3a4de
@ -534,7 +534,7 @@ function gr_draw_colorbar(cbar::GRColorbar, sp::Subplot, clims)
|
||||
GR.setwindow(xmin, xmax, zmin, zmax)
|
||||
if !isempty(cbar.gradients)
|
||||
series = cbar.gradients
|
||||
gr_set_gradient(_cbar_unique(gr_get_color.(series),"color"))
|
||||
gr_set_gradient(_cbar_unique(get_colorgradient.(series),"color"))
|
||||
gr_set_transparency(_cbar_unique(get_fillalpha.(series), "fill alpha"))
|
||||
GR.cellarray(xmin, xmax, zmax, zmin, 1, 256, 1000:1255)
|
||||
end
|
||||
@ -542,7 +542,7 @@ function gr_draw_colorbar(cbar::GRColorbar, sp::Subplot, clims)
|
||||
if !isempty(cbar.fills)
|
||||
series = cbar.fills
|
||||
GR.setfillintstyle(GR.INTSTYLE_SOLID)
|
||||
gr_set_gradient(_cbar_unique(gr_get_color.(series), "color"))
|
||||
gr_set_gradient(_cbar_unique(get_colorgradient.(series), "color"))
|
||||
gr_set_transparency(_cbar_unique(get_fillalpha.(series), "fill alpha"))
|
||||
levels = _cbar_unique(contour_levels.(series, Ref(clims)), "levels")
|
||||
# GR implicitly uses the maximal z value as the highest level
|
||||
@ -561,7 +561,7 @@ function gr_draw_colorbar(cbar::GRColorbar, sp::Subplot, clims)
|
||||
|
||||
if !isempty(cbar.lines)
|
||||
series = cbar.lines
|
||||
gr_set_gradient(_cbar_unique(gr_get_color.(series),"color"))
|
||||
gr_set_gradient(_cbar_unique(get_colorgradient.(series),"color"))
|
||||
gr_set_line(_cbar_unique(get_linewidth.(series), "line width"),
|
||||
_cbar_unique(get_linestyle.(series), "line style"),
|
||||
_cbar_unique(get_linecolor.(series, Ref(clims)), "line color"))
|
||||
@ -657,25 +657,10 @@ function gr_set_gradient(c)
|
||||
end
|
||||
|
||||
function gr_set_gradient(series::Series)
|
||||
color = gr_get_color(series)
|
||||
color = get_colorgradient(series)
|
||||
color !== nothing && gr_set_gradient(color)
|
||||
end
|
||||
|
||||
function gr_get_color(series::Series)
|
||||
st = series[:seriestype]
|
||||
if st in (:surface, :heatmap) || isfilledcontour(series)
|
||||
series[:fillcolor]
|
||||
elseif st in (:contour, :wireframe)
|
||||
series[:linecolor]
|
||||
elseif series[:marker_z] !== nothing
|
||||
series[:markercolor]
|
||||
elseif series[:line_z] !== nothing
|
||||
series[:linecolor]
|
||||
elseif series[:fill_z] !== nothing
|
||||
series[:fillcolor]
|
||||
end
|
||||
end
|
||||
|
||||
# this is our new display func... set up the viewport_canvas, compute bounding boxes, and display each subplot
|
||||
function gr_display(plt::Plot, fmt="")
|
||||
GR.clearws()
|
||||
|
||||
@ -200,12 +200,13 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
||||
# 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 hascolorbar(series)
|
||||
cg = get_colorgradient(series)
|
||||
cm = pgfx_colormap(get_colorgradient(series))
|
||||
PGFPlotsX.push_preamble!(
|
||||
pgfx_plot.the_plot,
|
||||
"""\\pgfplotsset{
|
||||
colormap={plots$(sp.attr[:subplot_index])}{$(pgfx_colormap(series.plotattributes[col]))},
|
||||
colormap={plots$(sp.attr[:subplot_index])}{$cm},
|
||||
}""",
|
||||
)
|
||||
push!(
|
||||
@ -213,10 +214,16 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
||||
"colorbar" => nothing,
|
||||
"colormap name" => "plots$(sp.attr[:subplot_index])",
|
||||
)
|
||||
if cg isa ColorPalette
|
||||
push!(
|
||||
axis_opt,
|
||||
"colormap access" => "piecewise const",
|
||||
"colorbar sampled" => nothing,
|
||||
)
|
||||
end
|
||||
# goto is needed to break out of col and series for
|
||||
@goto colorbar_end
|
||||
end
|
||||
end
|
||||
end
|
||||
@label colorbar_end
|
||||
|
||||
@ -677,13 +684,9 @@ function pgfx_filllegend!(series_opt, opt)
|
||||
}""")
|
||||
end
|
||||
|
||||
function pgfx_colormap(grad::Union{ColorGradient, ColorPalette})
|
||||
join(map(color_list(grad)) do c
|
||||
@sprintf("rgb=(%.8f,%.8f,%.8f)", red(c), green(c), blue(c))
|
||||
end, "\n")
|
||||
end
|
||||
function pgfx_colormap(grad::Vector{<:Colorant})
|
||||
join(map(grad) do c
|
||||
pgfx_colormap(cl::PlotUtils.AbstractColorList) = pgfx_colormap(color_list(cl))
|
||||
function pgfx_colormap(v::Vector{<:Colorant})
|
||||
join(map(v) do c
|
||||
@sprintf("rgb=(%.8f,%.8f,%.8f)", red(c), green(c), blue(c))
|
||||
end, "\n")
|
||||
end
|
||||
|
||||
@ -1000,6 +1000,8 @@ _backend_skips = Dict(
|
||||
16, # pgfplots thinks the upper panel is too small
|
||||
22, # contourf
|
||||
23, # pie
|
||||
25, # @df
|
||||
30, # @df
|
||||
31, # animation
|
||||
32, # spy
|
||||
38, # histogram2d
|
||||
|
||||
15
src/utils.jl
15
src/utils.jl
@ -541,6 +541,21 @@ for comp in (:line, :fill, :marker)
|
||||
end
|
||||
end
|
||||
|
||||
function get_colorgradient(series::Series)
|
||||
st = series[:seriestype]
|
||||
if st in (:surface, :heatmap) || isfilledcontour(series)
|
||||
series[:fillcolor]
|
||||
elseif st in (:contour, :wireframe)
|
||||
series[:linecolor]
|
||||
elseif series[:marker_z] !== nothing
|
||||
series[:markercolor]
|
||||
elseif series[:line_z] !== nothing
|
||||
series[:linecolor]
|
||||
elseif series[:fill_z] !== nothing
|
||||
series[:fillcolor]
|
||||
end
|
||||
end
|
||||
|
||||
single_color(c, v = 0.5) = c
|
||||
single_color(grad::ColorGradient, v = 0.5) = grad[v]
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user