cmap.set_under() and cmap.set_over() not appearing in colorbar

I am trying to plot a color bar and I tried using cmap.set_under() and cmap.set_over(), however they do not appear on the plot, can anyone help me please?

Here is the code:

city = 'Portugal, Lisbon' G = ox.graph_from_place(city, network_type='drive', simplify=True)  G_nx = nx.relabel.convert_node_labels_to_integers(G)  nc =[whatever you would like] ns=[whatever you would like]  cmap = copy(plt.cm.get_cmap('inferno_r')) cmap.set_over((0.001462, 0.000466, 0.013866, 1.0)) cmap.set_under((0.988362, 0.998364, 0.644924, 1.0)) norm=plt.Normalize(vmin=0.8, vmax=1.5) sm = mpl.cm.ScalarMappable(norm=norm, cmap=cmap) sm.set_array([])  fg_color = 'black' fig, ax = ox.plot.plot_graph(G_nx, node_color=nc, node_size=ns, edge_linewidth=0.8, figsize = (80,40), show=False, bgcolor = 'white') cb = fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap), ax=ax, orientation='vertical', aspect=50, shrink=0.8) cb.set_label('r', fontsize = 60, color = fg_color, rotation = 'horizontal') cb.ax.tick_params(labelsize=40, color = fg_color) # set colorbar tick color cb.ax.yaxis.set_tick_params(color=fg_color)   cb.outline.set_edgecolor(fg_color) cb.cmap.set_over('k')   plt.setp(plt.getp(cb.ax.axes, 'yticklabels'), color=fg_color)  fig.set_frameon(True) fig.savefig('dhgdhg.png', facecolor=fig.get_facecolor(), bbox_inches='tight') 

Thank you in advance

Add Comment
1 Answer(s)

fig.colorbar(..., extend='both') adds little triangular arrows at the top and the bottom of the colorbar, to indicate the over and the under color. Instead of ‘both’, other options are ‘min’ and ‘max’, the default is ‘neither’. For more info, see the docs.

Note that the default under color is equal to the lowest color of the colormap (similar for the default over color). In case these are the desired values, they don’t need to be set explicitly.

Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.