Skip to content

clabel not respecting zorder parameter #7957

@lzkelley

Description

To help us understand and resolve your issue, please fill out the form to the best of your ability. You can feel free to delete the sections that do not apply.

Bug report

Bug summary

Contour-line labels produced with plt.clabel are not respecting the zorder parameter, e.g. in the attached figure, the contour labels should be appearing above the grey lines.

clabel_test

Code for reproduction

import numpy as np
import matplotlib as mpl
from matplotlib import pyplot as plt

NX = 20
NY = 40
xvals = np.arange(NX)
yvals = np.arange(NY)
xgrid, ygrid = np.meshgrid(xvals, yvals)

def get_scalarmappable(min=0.0, max=1.0):
    cmap = 'Oranges'
    cmap = plt.get_cmap(cmap)
    norm = mpl.colors.Normalize(vmin=min, vmax=max)
    smap = mpl.cm.ScalarMappable(norm=norm, cmap=cmap)
    smap._A = []
    return smap

# Construct 2D Function to plot
hist = 1.0 - yvals[np.newaxis, :]/yvals.max() + np.power(xvals[:, np.newaxis]/xvals.max() - 0.5, 3.0)
min = hist.min()
max = hist.max()

# Load colormap
smap = get_scalarmappable(min=min, max=max)

# Construct Figure
fig, ax = plt.subplots(figsize=[8, 6])

# Plot grid
pcm = ax.pcolormesh(xgrid, ygrid, hist.T, norm=smap.norm, cmap=smap.cmap, linewidth=0,
                    rasterized=True, vmin=smap.norm.vmin, vmax=smap.norm.vmax)
pcm.set_edgecolor('face')

# Construct contour line (levels)
num = 3
levels = min + np.arange(1, num+1)*(max-min)/(num+1)

# Create grey backdrop for contour lines
ax.contour(xgrid, ygrid, hist.T, colors='0.50', norm=smap.norm,
           levels=levels, linewidths=6.0, antialiased=True, zorder=10)
# Plot colored contour lines
cs = ax.contour(xgrid, ygrid, hist.T, cmap=smap.cmap, norm=smap.norm,
                levels=levels, linewidths=2.5, antialiased=True, zorder=11, alpha=1.0)

# Plot contour-line labels (at a higher zorder than grey lines)
plt.clabel(cs, zorder=50, inline=True, fontsize=16, colors='0.8')

fig.savefig('clabel_test.png')

matplotlib 2.0.0 np111py35_0
Python 3.5.2 :: Anaconda custom (x86_64)
macOS Sierra 10.12.3 (16D32)
MacBook Pro (15-inch, Late 2016)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesGood first issueOpen a pull request against these issues if there are no active ones!

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions