FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[Bug]: Colorbar with drawedges=True and extend='both' does not draw edges at extremities · Issue #22864 · matplotlib/matplotlib · GitHub

Repository navigation

[Bug]: Colorbar with drawedges=True and extend='both' does not draw edges at extremities #22864

Description

Bug summary

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.

Code for reproduction

import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt  
from matplotlib.colors import from_levels_and_colors

my_cmap = mpl.cm.viridis
bounds = np.arange(10)
nb_colors = len(bounds) + 1
colors = 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)
plt.show()

Actual outcome

Expected outcome

Additional information

No response

Operating system

No response

Matplotlib Version

3.5.1

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

No response

Activity

  1. oscargus commented on Apr 20, 2022

    Member

    Fixed in #22865

  2. added this to the v3.6.0 milestone on Jun 15, 2022
  3. QuLogic commented on Jun 15, 2022

    Member

    @oscargus running the example from the OP on main, I see a boundary on the left side, but not the right side.

  4. modified the milestones: v3.6.0, v3.5.3 on Jun 15, 2022
  5. oscargus commented on Aug 3, 2022

    Member

    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?

  6. tacaswell commented on Aug 4, 2022

    Member

    @QuLogic and I talked about this on our checkin today. We think the solution is to turn off clipping on the dividers.

    import matplotlib as mpl
    import numpy as np
    import matplotlib.pyplot as plt  
    from matplotlib.colors import from_levels_and_colors
    
    my_cmap = mpl.cm.viridis
    bounds = np.arange(10)
    nb_colors = len(bounds) + 1
    colors = 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()
    
  7. tacaswell commented on Aug 4, 2022

    Member

    and in the Agg case there is definitly an issues with low dpi and pixel snapping.

  8. added 2 commits that reference this issue on Aug 4, 2022
    298a23f
    8fa6bd5
  9. added a commit that references this issue on Aug 10, 2022
    dcf7c0b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL