When creating a matplotlib colorbar, it is possible to set drawedges to True which separates the colors of the colorbar with black lines. However, when the colorbar is extended using extend='both', the black lines at the extremities do not show up.
So the right-most line is definitely included, not just drawn,,.
For the svg and pdf output, the first and last line are about half the width of the other lines. I am wondering if maybe there is something strange with the positioning.
Looking at the png, it is clear that the right-most tick is actually positioned what seems like a bit too far to the right:
So maybe the line is rendered below the extend patch? I am not really sure how to get around this?
@QuLogic and I talked about this on our checkin today. We think the solution is to turn off clipping on the dividers.
importmatplotlibasmplimportnumpyasnpimportmatplotlib.pyplotaspltfrommatplotlib.colorsimportfrom_levels_and_colorsmy_cmap=mpl.cm.viridisbounds=np.arange(10)
nb_colors=len(bounds) +1colors=my_cmap(np.linspace(100, 255, nb_colors).astype(int))
my_cmap, my_norm=from_levels_and_colors(bounds, colors, extend='both')
plt.figure(figsize=(5, 1))
ax=plt.subplot(111)
cbar=mpl.colorbar.ColorbarBase(ax, cmap=my_cmap, norm=my_norm, orientation='horizontal', drawedges=True)
plt.subplots_adjust(left=0.05, bottom=0.4, right=0.95, top=0.9)
cbar.dividers.set_lw(5)
cbar.dividers.set_clip_on(False) # drop this line and you see the lines cut in half at the edges.plt.show()
Activity
oscargus commented on Apr 20, 2022
Fixed in #22865
QuLogic commented on Jun 15, 2022
@oscargus running the example from the OP on main, I see a boundary on the left side, but not the right side.
oscargus commented on Aug 3, 2022
Sorry for not getting back to this until now. I can just confirm your observation. However,
In [3]: cbar.dividers.get_segments() Out[3]: [array([[0., 0.], [0., 1.]]), array([[1., 0.], [1., 1.]]), array([[2., 0.], [2., 1.]]), array([[3., 0.], [3., 1.]]), array([[4., 0.], [4., 1.]]), array([[5., 0.], [5., 1.]]), array([[6., 0.], [6., 1.]]), array([[7., 0.], [7., 1.]]), array([[8., 0.], [8., 1.]]), array([[9., 0.], [9., 1.]])]So the right-most line is definitely included, not just drawn,,.
For the svg and pdf output, the first and last line are about half the width of the other lines. I am wondering if maybe there is something strange with the positioning.
Looking at the png, it is clear that the right-most tick is actually positioned what seems like a bit too far to the right:

So maybe the line is rendered below the extend patch? I am not really sure how to get around this?
tacaswell commented on Aug 4, 2022
@QuLogic and I talked about this on our checkin today. We think the solution is to turn off clipping on the dividers.
tacaswell commented on Aug 4, 2022
and in the Agg case there is definitly an issues with low dpi and pixel snapping.
Don't clip colorbar dividers
Don't clip colorbar dividers
Don't clip colorbar dividers