working heatmap
This commit is contained in:
parent
0e94e57263
commit
4dd4d5eb5f
@ -711,7 +711,7 @@ const _pgfplotsx_attr = merge_with_base_supported([
|
|||||||
# :contour, :path3d, :scatter3d, :surface, :wireframe, :volume,
|
# :contour, :path3d, :scatter3d, :surface, :wireframe, :volume,
|
||||||
# :shape
|
# :shape
|
||||||
# ]
|
# ]
|
||||||
const _pgfplotsx_seriestype = [:path, :path3d, :scatter, :steppre, :stepmid, :steppost, :histogram2d, :ysticks, :xsticks, :contour, :shape, :straightline,]
|
const _pgfplotsx_seriestype = [:path, :path3d, :scatter, :steppre, :heatmap, :stepmid, :steppost, :histogram2d, :ysticks, :xsticks, :contour, :shape, :straightline,]
|
||||||
const _pgfplotsx_style = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
|
const _pgfplotsx_style = [:auto, :solid, :dash, :dot, :dashdot, :dashdotdot]
|
||||||
const _pgfplotsx_marker = [:none, :auto, :circle, :rect, :diamond, :utriangle, :dtriangle, :ltriangle, :rtriangle, :cross, :xcross, :star5, :pentagon, :hline, :vline, Shape]
|
const _pgfplotsx_marker = [:none, :auto, :circle, :rect, :diamond, :utriangle, :dtriangle, :ltriangle, :rtriangle, :cross, :xcross, :star5, :pentagon, :hline, :vline, Shape]
|
||||||
const _pgfplotsx_scale = [:identity, :ln, :log2, :log10]
|
const _pgfplotsx_scale = [:identity, :ln, :log2, :log10]
|
||||||
|
|||||||
@ -9,6 +9,19 @@ end
|
|||||||
|
|
||||||
pgfx_axes(pgfx_plot::PGFPlotsXPlot) = pgfx_plot.the_plot.elements[1].elements[1].contents
|
pgfx_axes(pgfx_plot::PGFPlotsXPlot) = pgfx_plot.the_plot.elements[1].elements[1].contents
|
||||||
|
|
||||||
|
function surface_to_vecs(x::AVec, y::AVec, s::Union{AMat, Surface})
|
||||||
|
a = Array(s)
|
||||||
|
xn = Vector{eltype(x)}(undef, length(a))
|
||||||
|
yn = Vector{eltype(y)}(undef, length(a))
|
||||||
|
zn = Vector{eltype(s)}(undef, length(a))
|
||||||
|
for (n, (i, j)) in enumerate(Tuple.(CartesianIndices(a)))
|
||||||
|
xn[n] = x[j]
|
||||||
|
yn[n] = y[i]
|
||||||
|
zn[n] = a[i,j]
|
||||||
|
end
|
||||||
|
return xn, yn, zn
|
||||||
|
end
|
||||||
|
|
||||||
function Base.show(io::IO, mime::MIME, pgfx_plot::PGFPlotsXPlot)
|
function Base.show(io::IO, mime::MIME, pgfx_plot::PGFPlotsXPlot)
|
||||||
show(io::IO, mime, pgfx_plot.the_plot)
|
show(io::IO, mime, pgfx_plot.the_plot)
|
||||||
end
|
end
|
||||||
@ -69,16 +82,32 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
|||||||
pgfx_axis!(axis_opt, sp, letter)
|
pgfx_axis!(axis_opt, sp, letter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if hascolorbar(sp)
|
# Search series for any gradient. In case one series uses a gradient set
|
||||||
PGFPlotsX.push_preamble!(pgfx_plot.the_plot, """\\pgfplotsset{
|
# the colorbar and colomap.
|
||||||
colormap={plots$(sp.attr[:subplot_index])}{$(pgfx_colormap(series.plotattributes[col]))},
|
# 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
|
||||||
pushed_colormap = true
|
# correctly displaying it.
|
||||||
push!(axis_opt,
|
# It's also possible to assign the colormap to the series itself but
|
||||||
"colorbar" => nothing,
|
# then the colormap needs to be added twice, once for the axis and once for the
|
||||||
"colormap name" => "plots$(sp.attr[:subplot_index])",
|
# series.
|
||||||
)
|
# As it is likely that all series within the same axis use the same
|
||||||
end
|
# 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
|
||||||
|
PGFPlotsX.push_preamble!(pgfx_plot.the_plot, """\\pgfplotsset{
|
||||||
|
colormap={plots$(sp.attr[:subplot_index])}{$(pgfx_colormap(series.plotattributes[col]))},
|
||||||
|
}""")
|
||||||
|
push!(axis_opt,
|
||||||
|
"colorbar" => nothing,
|
||||||
|
"colormap name" => "plots$(sp.attr[:subplot_index])",
|
||||||
|
)
|
||||||
|
# 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],
|
||||||
@ -101,11 +130,13 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
|||||||
opt = series.plotattributes
|
opt = series.plotattributes
|
||||||
st = series[:seriestype]
|
st = series[:seriestype]
|
||||||
series_opt = PGFPlotsX.Options(
|
series_opt = PGFPlotsX.Options(
|
||||||
"color" => opt[:linecolor],
|
"color" => single_color(opt[:linecolor]),
|
||||||
)
|
)
|
||||||
# function args
|
# function args
|
||||||
args = if st == :contour
|
args = if st == :contour
|
||||||
opt[:x], opt[:y], opt[:z].surf'
|
opt[:x], opt[:y], opt[:z].surf'
|
||||||
|
elseif st == :heatmap
|
||||||
|
surface_to_vecs(opt[:x], opt[:y], opt[:z])
|
||||||
elseif is3d(st)
|
elseif is3d(st)
|
||||||
opt[:x], opt[:y], opt[:z]
|
opt[:x], opt[:y], opt[:z]
|
||||||
elseif st == :straightline
|
elseif st == :straightline
|
||||||
@ -153,8 +184,21 @@ 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
|
elseif st == :heatmap
|
||||||
hist_
|
# TODO: global view setting
|
||||||
|
push!(axis.options,
|
||||||
|
"view" => "{0}{90}",
|
||||||
|
"shader" => "flat corner",
|
||||||
|
)
|
||||||
|
heatmap_opt = PGFPlotsX.Options(
|
||||||
|
"surf" => nothing,
|
||||||
|
"mesh/rows" => length(opt[:x])
|
||||||
|
)
|
||||||
|
heatmap_plot = PGFPlotsX.Plot3(
|
||||||
|
merge(series_opt, heatmap_opt),
|
||||||
|
PGFPlotsX.Table(args)
|
||||||
|
)
|
||||||
|
push!(axis, heatmap_plot)
|
||||||
else
|
else
|
||||||
# treat segments
|
# treat segments
|
||||||
segments = iter_segments(series)
|
segments = iter_segments(series)
|
||||||
@ -273,6 +317,11 @@ function pgfx_colormap(grad::ColorGradient)
|
|||||||
@sprintf("rgb=(%.8f,%.8f,%.8f)", red(c), green(c), blue(c))
|
@sprintf("rgb=(%.8f,%.8f,%.8f)", red(c), green(c), blue(c))
|
||||||
end,"\n")
|
end,"\n")
|
||||||
end
|
end
|
||||||
|
function pgfx_colormap(grad::Vector{<:Colorant})
|
||||||
|
join(map(grad) do c
|
||||||
|
@sprintf("rgb=(%.8f,%.8f,%.8f)", red(c), green(c), blue(c))
|
||||||
|
end,"\n")
|
||||||
|
end
|
||||||
|
|
||||||
function pgfx_framestyle(style::Symbol)
|
function pgfx_framestyle(style::Symbol)
|
||||||
if style in _pgfx_framestyles
|
if style in _pgfx_framestyles
|
||||||
|
|||||||
@ -74,7 +74,20 @@ end
|
|||||||
end # testset
|
end # testset
|
||||||
@testset "Histogram 2D" begin
|
@testset "Histogram 2D" begin
|
||||||
histogram2d(randn(10000), randn(10000), nbins=20)
|
histogram2d(randn(10000), randn(10000), nbins=20)
|
||||||
# TODO: totally broken, errors also for pgfplots
|
# TODO: should work, when heatmaps works?
|
||||||
|
end # testset
|
||||||
|
@testset "Heatmap" begin
|
||||||
|
xs = [string("x", i) for i = 1:10]
|
||||||
|
ys = [string("y", i) for i = 1:4]
|
||||||
|
z = float((1:4) * reshape(1:10, 1, :))
|
||||||
|
pgfx_plot = heatmap(xs, ys, z, aspect_ratio=1)
|
||||||
|
Plots._update_plot_object(pgfx_plot)
|
||||||
|
if @test_nowarn(haskey(Plots.pgfx_axes(pgfx_plot.o)[1].options.dict, "colorbar") == true)
|
||||||
|
@test Plots.pgfx_axes(pgfx_plot.o)[1]["colorbar"] === nothing
|
||||||
|
@test Plots.pgfx_axes(pgfx_plot.o)[1]["colormap name"] == "plots1"
|
||||||
|
end
|
||||||
|
# TODO: wrong colors
|
||||||
|
# TODO: lines instead of patches
|
||||||
end # testset
|
end # testset
|
||||||
@testset "Contours" begin
|
@testset "Contours" begin
|
||||||
x = 1:0.5:20
|
x = 1:0.5:20
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user