如何让我的 Cartopy 颜色条具有我设置的特定范围?
How do I make my colour bar for Cartopy have a specific range set by me?
我正在比较各种任务,我希望颜色条具有我设置的最大值和最小值。我不确定该怎么做,有什么帮助吗?任务本身会保持在一个范围内,但我想设置它,所以很容易比较。有些任务不同,有些则不同,所以我不希望计算机自动设置最大值和最小值。
crs_latlon = ccrs.PlateCarree()
def make_plot(projection_name, projection_crs):
ax = plt.axes(projection=projection_crs)
#ax.set_extent((-65.0, -58, 40, 47.7), crs=crs_latlon)
ax.set_extent((-65.0, -62, 43, 45.5), crs=crs_latlon)
#Add coastlines and meridians/parallels (Cartopy-specific).
plt.gca().coastlines('10m')
ax.gridlines(crs=crs_latlon, linestyle='-')
# Add a title, legend, and display.
ax.set_title(''.join(("Mission #13: Attenuation Coeffiecient - ",
projection_name)))
cb = plt.scatter(avglonlist, avglatlist, c=klist, cmap=coolwarm)
plt.colorbar(cb, cmap=coolwarm, orientation='vertical',ticklocation='auto')
#plt.colorbar.ColorbarBase(ax=ax, cmap = coolwarm, orientation='vertical', ticklocation='auto',
# norm=plt.colors.Normalize(vmin=0, vmax=1))
iplt.show()
def main():
# Demonstrate with two different display projections.
make_plot('Equidistant Cylindrical', ccrs.PlateCarree())
graph_my_latandk(avglatlist,klist)
if __name__ == '__main__':
main()
我猜你必须像这里一样创建你的 own color bar:
import matplotlib.pylab as plt
from matplotlib import colorbar, colors
fig = plt.figure(figsize=(8, 3))
ax = fig.add_axes([.05, .05, .05, .7]) # position of colorbar
cbar = colorbar.ColorbarBase(ax, cmap=plt.get_cmap('coolwarm'),
norm=colors.Normalize(vmin=-.5, vmax=1.5)) # set min, max of colorbar
cbar.set_clim(-.5, .5) # set limits of color map
plt.show()
vmin, vmax
允许设置颜色条的限制,但 clim
允许设置颜色图的限制。
如果将vmin和vmax传给scatter,可以设置散点图的颜色范围,colourbar也会相应设置。
例如
cb = plt.scatter(avglonlist, avglatlist, c=klist, cmap=coolwarm, vmin=-4, vmax=2)
plt.colorbar(cb, cmap=coolwarm, orientation='vertical',ticklocation='auto')
我正在比较各种任务,我希望颜色条具有我设置的最大值和最小值。我不确定该怎么做,有什么帮助吗?任务本身会保持在一个范围内,但我想设置它,所以很容易比较。有些任务不同,有些则不同,所以我不希望计算机自动设置最大值和最小值。
crs_latlon = ccrs.PlateCarree()
def make_plot(projection_name, projection_crs):
ax = plt.axes(projection=projection_crs)
#ax.set_extent((-65.0, -58, 40, 47.7), crs=crs_latlon)
ax.set_extent((-65.0, -62, 43, 45.5), crs=crs_latlon)
#Add coastlines and meridians/parallels (Cartopy-specific).
plt.gca().coastlines('10m')
ax.gridlines(crs=crs_latlon, linestyle='-')
# Add a title, legend, and display.
ax.set_title(''.join(("Mission #13: Attenuation Coeffiecient - ",
projection_name)))
cb = plt.scatter(avglonlist, avglatlist, c=klist, cmap=coolwarm)
plt.colorbar(cb, cmap=coolwarm, orientation='vertical',ticklocation='auto')
#plt.colorbar.ColorbarBase(ax=ax, cmap = coolwarm, orientation='vertical', ticklocation='auto',
# norm=plt.colors.Normalize(vmin=0, vmax=1))
iplt.show()
def main():
# Demonstrate with two different display projections.
make_plot('Equidistant Cylindrical', ccrs.PlateCarree())
graph_my_latandk(avglatlist,klist)
if __name__ == '__main__':
main()
我猜你必须像这里一样创建你的 own color bar:
import matplotlib.pylab as plt
from matplotlib import colorbar, colors
fig = plt.figure(figsize=(8, 3))
ax = fig.add_axes([.05, .05, .05, .7]) # position of colorbar
cbar = colorbar.ColorbarBase(ax, cmap=plt.get_cmap('coolwarm'),
norm=colors.Normalize(vmin=-.5, vmax=1.5)) # set min, max of colorbar
cbar.set_clim(-.5, .5) # set limits of color map
plt.show()
vmin, vmax
允许设置颜色条的限制,但 clim
允许设置颜色图的限制。
如果将vmin和vmax传给scatter,可以设置散点图的颜色范围,colourbar也会相应设置。
例如
cb = plt.scatter(avglonlist, avglatlist, c=klist, cmap=coolwarm, vmin=-4, vmax=2)
plt.colorbar(cb, cmap=coolwarm, orientation='vertical',ticklocation='auto')