You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Colorbar with drawedges=True and extend='both' does not draw edges at extremities #22864
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 commentedon Apr 20, 2022
Fixed in #22865
QuLogic commentedon 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 commentedon Aug 3, 2022
Sorry for not getting back to this until now. I can just confirm your observation. However,
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 commentedon 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 commentedon 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