Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clabel randomly inconsistend when placed manually #3565

Closed
dcrabs opened this issue Sep 25, 2014 · 2 comments
Closed

clabel randomly inconsistend when placed manually #3565

dcrabs opened this issue Sep 25, 2014 · 2 comments

Comments

@dcrabs
Copy link

dcrabs commented Sep 25, 2014

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

@dcrabs
Copy link
Author

dcrabs commented Sep 25, 2014

Well, it seems it is the y axis that is relevant not the value of the contour.

@dcrabs dcrabs closed this as completed Sep 25, 2014
@tacaswell
Copy link
Member

As a bit of clairification:

manual:

if True, contour labels will be placed manually using mouse clicks. Click the first button near a contour to add a label, click the second button (or potentially both mouse buttons at once) to finish adding labels. The third button can be used to remove the last label added, but only if labels are not inline. Alternatively, the keyboard can be used to select label locations (enter to end label placement, delete or backspace act like the third mouse button, and any other key will select a label location).

manual can be an iterable object of x,y tuples. Contour labels will be created as if mouse is clicked at each x,y positions.

So it is putting labels as close as possible to the x,y locations as possible (and sorting out which contour and it's label) internally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants