The following code will plot what I wish to see, but I was wondering how to edit the colorbar so that it has a title?
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
x = []
y = []
z = []
with open('TEMP.txt', 'r') as csvfile:
plots = csv.reader(csvfile, delimiter="\t")
for row in plots:
x.append(float(row[0]))
y.append(float(row[1]))
z.append(float(row[2]))
m = Basemap(projection='stere',lat_ts = -25, lat_0 = -25.27 , lon_0 = 133.77, resolution='l',width=14000000, height=10000000)
m.drawcoastlines()
m.drawparallels(np.arange(-80, 80, 20))
m.drawmeridians(np.arange(-180, 181, 20))
m.fillcontinents(color='coral')
lats = x
lons = y
time = z
x, y = m(lons,lats)
sc = m.scatter(x,y,60,z,cmap='jet',marker='o')
plt.colorbar(sc)
plt.show()
There are two different ways you can do this. This first is as suggested by @umutto in the comments which is using set_label
. The second is using ax.set_title
, however there are some differences in the default position of the labels.
plt.imshow(np.random.randn(25).reshape(5,5))
cb = plt.colorbar()
cb.set_label("Test 1", rotation=270)
cb.ax.set_title("Test 2")
plt.show()
This produces the following figure:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.