Issue
I am trying to manually place contour labels using matplotlib.pyplot.clabel
as follows:
import matplotlib.pyplot as plt
import numpy as np
# Make example contours
N=20
X = np.linspace(0.0, 10.0, N)
Y = np.linspace(0.0, 25.0, N)
Z = np.ones((N,N))
i=0
j=0
for i in range(N):
for j in range(N):
Z[i][j] = i+j
j += 1
i += 1
Z = Z.transpose()
# Make subplots figure
fig, axes = plt.subplots(2, 1, sharex=True, figsize=(8,5))
im = axes[0].contour(X, Y, Z, colors = 'k')
CLS = plt.clabel(im, colors = 'k', fmt = '%2.1f', fontsize=12, manual=True)
im2 = axes[1].contourf(X, Y, Z)
fig.show()
This code produces the following figure, which adds contour labels to the different contours as you left-click on them:
The message on the console as python tracks the clicks is:
Select label locations manually using first mouse button. End manual selection with second mouse button.
The problem is that the right-click does not end the event recording, and I am unable to go past this point in the script at run time. I have tried this both on Windows and Mac using Spyder, and the second mouse button is not recorded.
EDIT 1: As @ImportanceOfBeingErnest pointed out, the second mouse button is actually the scroll wheel, not the right button. I have decided to leave the question as is because I think this is not clear for every user of matplotlib.
I would like to know how to end the manual selection process so that the program continues and I am able to retrieve a figure like this:
but with contour labels, of course. I have tried this process with figure plotter in Automatic, Tkinter and Qt5, with no success.
Solution
As @ImportanceOfBeingErnest said, the second mouse button is actually the scroll wheel, not the right button. If you have a mouse with all three buttons then this is the solution.
For Mac users with a Magic Mouse, the solution is not as straightforward. I was able to make it work with the 3rd party application BetterTouchTool. Once downloaded, go to System Preferences >> Security & Privacy. Under the section Allow the apps below to control your computer., enable BetterTouchTool.
Then, open the app and under Select Trigger choose 1 Finger Middle Click. Then on the right, under the section Actions Assigned to Selected Trigger, choose Middle Click. Once this is done, pushing the middle of the Magic Button will do the trick:
Answered By - Bremsstrahlung
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.