# UndefVarError: \`colorbar\` not defined while using Plots.jl

**URL:** <https://discourse.julialang.org/t/undefvarerror-colorbar-not-defined-while-using-plots-jl/111784>\
**Category:** Visualization\
**Tags:** plots\
**Created:** [March 18, 2024, 5:25pm UTC](https://discourse.julialang.org/t/undefvarerror-colorbar-not-defined-while-using-plots-jl/111784 "2024-03-18T17:25:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [March 18, 2024, 5:25pm UTC](https://discourse.julialang.org/t/undefvarerror-colorbar-not-defined-while-using-plots-jl/111784/1 "2024-03-18T17:25:08Z")

</div>

While using Plots.jl i am getting error **UndefVarError: `colorbar` not defined**  
Please code below 👉

```julia
begin
	fig = plot(size=(300, 300)) # figsize=(20, 20)
	ax = fig[1]
	
	# Define colormap
	colormap = :jet
	
	# Set plot limits and aspect ratio
	xlims!(ax, (0, x_lim))
	ylims!(ax, (0, y_lim))
	aspect_ratio=print(ax)
	
	# Define color range for density plot
	vmin = 1e-8
	vmax = 1e-2
	
	# Create density plot
	print(size(rho[1,:,:] .* v_p[1,:,:]))
	density2 = heatmap!( rho[1,:,:] .* v_p[1,:,:], cbar=true, clim=(log(vmin), log(vmax)), xlabel="X", ylabel="Z", title="Density vs X-Z")
	
	# Create contour plot
	contour!( psi[1,:,:], levels=contour_levels, linecolor=:white, linewidth=4)
	
	# Add colorbar
	cbr = colorbar(density, label=L"\mathbf{\rm{log}_{10}(\rho{\rm v_p})}", 
	   ticks=[log10(vmin), 0, log10(vmax)], ticklabels=["$vmin", "1", "$vmax"])
	
	# Save the plot
	savefig("plot.png")
	@show density2
end

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [March 18, 2024, 6:21pm UTC](https://discourse.julialang.org/t/undefvarerror-colorbar-not-defined-while-using-plots-jl/111784/2 "2024-03-18T18:21:15Z")

</div>

Why do you think this function should exist? Can you link to some documentation showing the usage?

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [March 19, 2024, 3:57am UTC](https://discourse.julialang.org/t/undefvarerror-colorbar-not-defined-while-using-plots-jl/111784/3 "2024-03-19T03:57:22Z")

</div>

In [Subplot Attributes · Plots](https://docs.juliaplots.org/stable/generated/attributes_subplot/) there is `colorbar`. What else should i use instead of `colorbar`?

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [March 19, 2024, 7:59am UTC](https://discourse.julialang.org/t/undefvarerror-colorbar-not-defined-while-using-plots-jl/111784/4 "2024-03-19T07:59:34Z")

</div>

That’s not a function but an attribute - i.e. `plot(some_data; colorbar = some_colorbar)`

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [March 19, 2024, 8:31am UTC](https://discourse.julialang.org/t/undefvarerror-colorbar-not-defined-while-using-plots-jl/111784/5 "2024-03-19T08:31:45Z")

</div>

But i am using `heatmap()` and how can include it?
