My current code looks like this:
import matplotlib.pyplot as plt
import numpy as np
s = 5
x = np.linspace(-10,10,100)
y = np.linspace(-10,10,100)
xg = np.exp(-(x**2)/(s**2))
yg = np.exp(-(y**2)/(s**2))
vals = np.meshgrid(xg,yg)
fig, ax = plt.subplots()
cax = ax.imshow(vals[0]*vals[1])
ax.axis("off")
fig.colorbar(cax,ticks=[0.0,1.0],label="Values (0-1)")
Which produces the following output:
I would like the tick values to be on top and bottom of the colorbar (and not on the sides) as in here:
At the moment, I have done this using Illustrator but I am planning to generate a lot of images like this (for a video) and would like to make these plots automatic.
If you want them nicely centered on the colorbar, then you can't use the yticklabels to achieve this. But you can add the two text fields manually like this:
cb = plt.colorbar(im, ticks=[], label="Values (0-1)")
cb.ax.text(0.5, -0.01, '0', transform=cb.ax.transAxes,
va='top', ha='center')
cb.ax.text(0.5, 1.0, '1', transform=cb.ax.transAxes,
va='bottom', ha='center')
Result:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With