I am trying to change the colorbar position:
using Plots
# pyplot()
plot(rand(10, 2), marker_z=rand(10), seriestype=:scatter, cb=:top)
But the colorbar position won’t move no matter how I specifiy :cb
:
It is always on the right side of the image.
I tried using Plots and PyPlot backends, in terminal and IJulia both, which all didn’t work. All the package are up-to-date. Any ideas how may I achieve this? Thanks in advance.
1 Like
I am facing the same issue, any trick to go around this issue?
Positioning the colorbar can be tricky since some plotting packages do not support any position except to the right of the plot. But as one method, you can use PyPlot.jl directly and place the colorbar underneath the plot, e.g.,:
using PyPlot
fig, ax = plt.subplots(figsize=(4,4))
mesh = ax.pcolormesh(rand(10, 10))
fig.colorbar(mesh, orientation="horizontal")
gcf()
This does now work with pyplot backend:
Fyi, the plot(colorbar=:top)
argument also works with the pgfplotsx()
backend.
But the colorbar title is still weird for this. It will go to the left of the bar…
Plots.jl can be tamed using Measures and layouts:
using Measures, Plots; pgfplotsx()
l = @layout [a{0.1h}; b]
p1 = plot(frame=:none, title="CB title", titlefontsize=10, bottom_margin=-25mm);
p2 = plot(rand(10,2), marker_z=rand(10), st=:scatter, cb=:top);
plot(p1, p2, layout=l)
1 Like