Heat map in Julia

Viewed 340

I am a new user and have no idea how to solve this error:

using AbstractGPs
using LinearAlgebra
using Plots
using Random
using PlutoUI

randomseed=42

Random.seed!(randomseed)

X = rand(datapoints) .* 2 .- 1
PES(x)=x^2

plot(-1:0.01:1, PES, label="Underlying potential", xlabel="Position", ylabel="Energy")

Y = PES.(X)

kernelfunction=SEKernel()
Xrange=range(-3,3; length=100)

plot(heatmap(kernelmatrix(kernelfunction, Xrange); yflip=true))

Stack trace:

MethodError: no method matching Val{:heatmap}(::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char)

1. apply_recipe(::Dict{Symbol,Any}, ::Type{Val{:heatmap}}, ::Plots.Plot{Plots.GRBackend})@recipes.jl:49
2. _process_plotrecipe(::Any, ::Any, ::Any, ::Any)@plot_recipe.jl:32
3. _process_plotrecipes!(::Any, ::Any)@plot_recipe.jl:18
4. recipe_pipeline!(::Any, ::Any, ::Any)@RecipesPipeline.jl:81
5. _plot!(::Plots.Plot, ::Any, ::Any)@plot.jl:208
6. #plot#154@plot.jl:91[inlined]
7. #heatmap#406(::Any, ::typeof(Plots.heatmap), ::Any)@RecipesBase.jl:404
8. top-level scope@Local: 2[inlined]
1 Answers

Not sure what you did wrong but this

using AbstractGPs, LinearAlgebra, Plots, Random # removed PlutoUI

randomseed = 42
Random.seed!(randomseed)

datapoints = 100 # Added for code to be self-contained

X = rand(datapoints) .* 2 .- 1
PES(r) = r^2

# removed first plot

Y = PES.(X)
kernelfunction = SEKernel()
Xrange = range(-3, 3; length=100)

heatmap(kernelmatrix(kernelfunction, Xrange); yflip=true) # removed unnecessary call to `plot`

gives me

enter image description here

Related