Skip to content

clabel randomly inconsistend when placed manually #3565

Closed
@dcrabs

Description

@dcrabs

Setting more than 4 labels manually with clabel in contourplot results in "random" distribution of labels across contours.

import numpy as np
import matplotlib.pyplot as plt

a = 0.2
resolution = 100
xarray = np.linspace(0,0.25,num=resolution)
yarray = np.linspace(0,1,num=resolution)

A = np.empty([resolution,resolution])

xc = 0
yc = 0
for x in xarray:
    for y in yarray:
        #print xc,yc

        wp = 1./np.pi*np.arctan(np.sin(np.pi*y)*np.sinh(np.pi*a/2.)/
              (np.cosh(np.pi*x)-np.cos(np.pi*y)*np.cosh(np.pi*a/2.)))

        if wp <= 0:
            wp = wp+1
            A[xc, yc] = wp
        else:
            A[xc, yc] = wp
        yc += 1
    yc=0
    xc += 1

A = A.transpose()
B = np.fliplr(A)
AB = np.hstack((B,A))
fullx = np.hstack((-xarray[::-1],xarray))

#plot
CS = plt.contour(fullx,yarray,AB,10, colors='k')

labelpos = np.dstack((np.zeros(9),np.arange(0.1,1,0.1)))[0]
plt.clabel(CS,inline=True, fmt='%1.1f',fontsize=9, manual=labelpos)

plt.show()

test

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions