Hi everyone! First time posting here. I’m trying to rotate the labels in the colorbar with pygmt. I tried adding -S option from GMT doc and adding +a45 to the position and frame variables in pygmt but no success.
# Add a colorbar for the elevation
fig.colorbar(
# Place the colorbar outside the plot (upper-case "J")
# Move the x label above the horizontal colorbar ("+ml")
position = ["JMR+o1c/-0.1c+w14c/0.4c+ml"],
# Add a box around the colobar with a fill ("+g") in "white" color and
# a transparency ("@") of 8 %
box="+gwhite@8",
# Add x and y labels ("+l")
frame=["xa2000f1000","x+lElevation", "y+lm"],
)
I just tried a simple code example. Here, appending +a to the frame parameter of Figure.colorbar works. Maybe this example can already help you to adjust your code. Otherwise please post your code, in which you try to rotate the annotations of the colorbar.
Yes, that’s true. Rotated anntotations are only available for Carthesian plots (4. Standardized command line options — GMT 6.6.0 documentation). And it looks like this applies not only the the frame of the figure or map, but also for the frame of the colorbar.
So far, I only have a very rude work around. There, the projection is changed to Cartesian before plotting the colorbar. Playing around with Figure.shift_origin can be also helpful.
import pygmt
fig = pygmt.Figure()
# Basemap with none Cartesian projection
fig.basemap(region=[115, 119.5, 4, 7.5], projection="M15c", frame=True)
# !!! This is not a nice solution !!!
# !!! Be aware of that the projection changes now !!!
# First plot the map frame in red to adjust the size of the Cartesian projection
#with pygmt.config(MAP_FRAME_PEN="red"):
# In the end make the frame completely transparent (@100) to hide it
with pygmt.config(MAP_FRAME_PEN="red@100"):
# We need a basemap with a Cartesian projection to be allowed to rotate
# the annotations of the colorbar
# The size of this projection is manually adjusted based on the width and
# height of the projection used for the map at the beginning
fig.basemap(region=[-1, 1] * 2, projection="X15c/11.5c", frame=0)
fig.colorbar(cmap="batlow", position="JRM+ml+w10c/0.4c", frame="xaf+a90+lElevation")
# !!! Every data you plot now is plotted with a Cartesian projection !!!
fig.show()