I am trying to draw a surface plot in Julia. What I want is for the color of the surface to match the vertical-axis value, and for this to range from deep red (negative) to deep blue (positive), with white when vertical (pi - c) = 0.
I am able to draw the graph no problem, and even adjust the clim in the Plot function. However, the actual colors on the graph do not match the colorbar in the legend: clim only affects the legend but does not change the color of the surface.
Here is an image to fix ideas. Note that all values on the vertical-axis are negative, yet the surface is white even when the vertical value = -0.9, while the legend on the right is doing what I want it to do.
And here is the code:
using Plots
# Paramters
A = 1
αω = 0.5
αz = 0.5
β1 = 1
β2 = 1
β0 = 0
γ = 1
# Functions
π(ω,z) = A*ω^(αω)*z^(-αz)
c(x) = β1*x + β2*x^2 + β0
p(x) = 1 - exp(-γ*x);
F(x,Ω=Ω, Z=Z) = [π(ω_val, z_val) for ω_val in Ω, z_val in Z] .- [c(x) for ω_val in Ω, z_val in Z]
# Grids
Ω = range(0, 1, length=101)
Z = range(0.4, 1, length=101)
function plot_f(x, Ω=Ω, Z=Z)
# Compute f(ω,z) = π(ω,z) - c(x) for each pair of ω and z values
f_values = F(x,Ω,Z)
# Compute the maximum absolute value of f_values
max_abs = float(maximum(abs.(f_values)))
# Create a 3D surface plot of f(ω,z) for the given value of x, with the colormap fixed at 0 for the white portion
plot(Z,Ω,f_values,xlabel="z", ylabel="ω", zlabel="π(ω,z) - c($x)",
st=:surface,camera=(30,30),
cmap=:RdBu,clim=(-max_abs, max_abs),
title="Current-period profit when x=$x")
end
plot_f(0.9)
I am sure I am doing something silly. How do I make the surface match the legend?