SourceForge logo
SourceForge logo
Menu

matplotlib-users — Discussion related to using matplotlib

You can subscribe to this list here.

2003 Jan
Feb
Mar
Apr
May
(3)
Jun
Jul
Aug
(12)
Sep
(12)
Oct
(56)
Nov
(65)
Dec
(37)
2004 Jan
(59)
Feb
(78)
Mar
(153)
Apr
(205)
May
(184)
Jun
(123)
Jul
(171)
Aug
(156)
Sep
(190)
Oct
(120)
Nov
(154)
Dec
(223)
2005 Jan
(184)
Feb
(267)
Mar
(214)
Apr
(286)
May
(320)
Jun
(299)
Jul
(348)
Aug
(283)
Sep
(355)
Oct
(293)
Nov
(232)
Dec
(203)
2006 Jan
(352)
Feb
(358)
Mar
(403)
Apr
(313)
May
(165)
Jun
(281)
Jul
(316)
Aug
(228)
Sep
(279)
Oct
(243)
Nov
(315)
Dec
(345)
2007 Jan
(260)
Feb
(323)
Mar
(340)
Apr
(319)
May
(290)
Jun
(296)
Jul
(221)
Aug
(292)
Sep
(242)
Oct
(248)
Nov
(242)
Dec
(332)
2008 Jan
(312)
Feb
(359)
Mar
(454)
Apr
(287)
May
(340)
Jun
(450)
Jul
(403)
Aug
(324)
Sep
(349)
Oct
(385)
Nov
(363)
Dec
(437)
2009 Jan
(500)
Feb
(301)
Mar
(409)
Apr
(486)
May
(545)
Jun
(391)
Jul
(518)
Aug
(497)
Sep
(492)
Oct
(429)
Nov
(357)
Dec
(310)
2010 Jan
(371)
Feb
(657)
Mar
(519)
Apr
(432)
May
(312)
Jun
(416)
Jul
(477)
Aug
(386)
Sep
(419)
Oct
(435)
Nov
(320)
Dec
(202)
2011 Jan
(321)
Feb
(413)
Mar
(299)
Apr
(215)
May
(284)
Jun
(203)
Jul
(207)
Aug
(314)
Sep
(321)
Oct
(259)
Nov
(347)
Dec
(209)
2012 Jan
(322)
Feb
(414)
Mar
(377)
Apr
(179)
May
(173)
Jun
(234)
Jul
(295)
Aug
(239)
Sep
(276)
Oct
(355)
Nov
(144)
Dec
(108)
2013 Jan
(170)
Feb
(89)
Mar
(204)
Apr
(133)
May
(142)
Jun
(89)
Jul
(160)
Aug
(180)
Sep
(69)
Oct
(136)
Nov
(83)
Dec
(32)
2014 Jan
(71)
Feb
(90)
Mar
(161)
Apr
(117)
May
(78)
Jun
(94)
Jul
(60)
Aug
(83)
Sep
(102)
Oct
(132)
Nov
(154)
Dec
(96)
2015 Jan
(45)
Feb
(138)
Mar
(176)
Apr
(132)
May
(119)
Jun
(124)
Jul
(77)
Aug
(31)
Sep
(34)
Oct
(22)
Nov
(23)
Dec
(9)
2016 Jan
(26)
Feb
(17)
Mar
(10)
Apr
(8)
May
(4)
Jun
(8)
Jul
(6)
Aug
(5)
Sep
(9)
Oct
(4)
Nov
Dec
2017 Jan
(5)
Feb
(7)
Mar
(1)
Apr
(5)
May
Jun
(3)
Jul
(6)
Aug
(1)
Sep
Oct
(2)
Nov
(1)
Dec
2018 Jan
Feb
Mar
Apr
(1)
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2020 Jan
Feb
Mar
Apr
May
(1)
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2025 Jan
(1)
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
S M T W T F S


1
(8)
2
(7)
3
(8)
4
(12)
5
(1)
6
(1)
7
(9)
8
(2)
9
10
(1)
11
12
(6)
13
(6)
14
(2)
15
(7)
16
(10)
17
18
(3)
19
(4)
20
(4)
21
(10)
22
(8)
23
(17)
24
(13)
25
(9)
26
(1)
27
(1)
28
(4)
29
(7)
30
(2)
31
(10)


Showing 6 results of 6

From: Jeff W. <js...@fa...> - 2012年05月13日 14:03:08
On 5/13/12 3:34 AM, David Craig wrote:
> Hi, I'm having a problem usinf fill_between() with basemap. I plot two 
> great circles and want to shade the region between them. My code is 
> below, it doesnt give any error just creates the plot without filling 
> the area. Does anyone know if it's possible to do this or should I try 
> a different method?
> Thanks,
> David
>
David Try replacing
m.drawgreatcircle(x1, y1, x2, y2, del_s=10, color='gray', lw=1.)
m.drawgreatcircle(x1, y1, x3, y3, del_s=10, color='gray', lw=1.)
a=linspace(x3,x1)
b=linspace(y2,y1)
c=linspace(y3,y1)
fill_between(a, b, c, where=None, alpha=0.2)
with
xx1,yy1 = m.gcpoints(x1,y1,x2,y2,100)
xx2,yy2 = m.gcpoints(x1,y1,x3,y3,100)
fill_between(xx1, yy1, yy2)
-Jeff
> from mpl_toolkits.basemap import Basemap
> from pylab import *
>
> ### PARAMETERS FOR MATPLOTLIB :
> import matplotlib as mpl
> rcParams['font.size'] = 10.
> rcParams['font.family'] = 'Comic Sans MS'
> rcParams['axes.labelsize'] = 8.
> rcParams['xtick.labelsize'] = 6.
> rcParams['ytick.labelsize'] = 6.
>
> def shoot(lon, lat, azimuth, maxdist=None):
> """Shooter Function
> Original javascript on http://williams.best.vwh.net/gccalc.htm
> Translated to python by Thomas Lecocq
> """
> glat1 = lat * pi / 180.
> glon1 = lon * pi / 180.
> s = maxdist / 1.852
> faz = azimuth * pi / 180.
>
> EPS= 0.00000000005
> if ((abs(cos(glat1))<EPS) and not (abs(sin(faz))<EPS)):
> alert("Only N-S courses are meaningful, starting at a pole!")
>
> a=6378.13/1.852
> f=1/298.257223563
> r = 1 - f
> tu = r * tan(glat1)
> sf = sin(faz)
> cf = cos(faz)
> if (cf==0):
> b=0.
> else:
> b=2. * arctan2 (tu, cf)
>
> cu = 1. / sqrt(1 + tu * tu)
> su = tu * cu
> sa = cu * sf
> c2a = 1 - sa * sa
> x = 1. + sqrt(1. + c2a * (1. / (r * r) - 1.))
> x = (x - 2.) / x
> c = 1. - x
> c = (x * x / 4. + 1.) / c
> d = (0.375 * x * x - 1.) * x
> tu = s / (r * a * c)
> y = tu
> c = y + 1
> while (abs (y - c) > EPS):
>
> sy = sin(y)
> cy = cos(y)
> cz = cos(b + y)
> e = 2. * cz * cz - 1.
> c = y
> x = e * cy
> y = e + e - 1.
> y = (((sy * sy * 4. - 3.) * y * cz * d / 6. + x) *
> d / 4. - cz) * sy * d + tu
>
> b = cu * cy * cf - su * sy
> c = r * sqrt(sa * sa + b * b)
> d = su * cy + cu * sy * cf
> glat2 = (arctan2(d, c) + pi) % (2*pi) - pi
> c = cu * cy - su * sy * cf
> x = arctan2(sy * sf, c)
> c = ((-3. * c2a + 4.) * f + 4.) * c2a * f / 16.
> d = ((e * cy * c + cz) * sy * c + y) * sa
> glon2 = ((glon1 + x - (1. - c) * d * f + pi) % (2*pi)) - pi
>
> baz = (arctan2(sa, b) + pi) % (2 * pi)
>
> glon2 *= 180./pi
> glat2 *= 180./pi
> baz *= 180./pi
>
> return (glon2, glat2, baz)
>
> #Create a basemap around N. Atlantic
> m = Basemap(llcrnrlon=-45.0,llcrnrlat=30.0,urcrnrlon=15.0,urcrnrlat=75.0,
> resolution='i',projection='merc',lon_0=-17.5,lat_0=60.0)
>
>
> m.drawcountries(linewidth=0.5)
> m.drawcoastlines(linewidth=0.5)
> m.bluemarble()
> m.drawparallels(arange(40.,75.,10.),labels=[1,0,0,0],color='black',dashes=[1,0],labelstyle='+/-',linewidth=0.2) 
> # draw parallels
> m.drawmeridians(arange(-45.,15.,10.),labels=[0,0,0,1],color='black',dashes=[1,0],labelstyle='+/-',linewidth=0.2) 
> # draw meridians
>
> # Shade region defined by great circles.
> x1, y1 = -9.1676613, 51.6029999
> az1 = 270.
> az2 = 290.
> maxdist = 2000
> x2, y2, baz = shoot(x1, y1, az1, maxdist)
> x3, y3, baz = shoot(x1, y1, az2, maxdist)
>
> m.drawgreatcircle(x1, y1, x2, y2, del_s=10, color='gray', lw=1.)
> m.drawgreatcircle(x1, y1, x3, y3, del_s=10, color='gray', lw=1.)
> a=linspace(x3,x1)
> b=linspace(y2,y1)
> c=linspace(y3,y1)
> fill_between(a, b, c, where=None, alpha=0.2)
> show()
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>
>
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: Jerzy K. <jer...@un...> - 2012年05月13日 11:15:36
Appendix.
(and excuses for my approximate syntax in the first message; I was doing 
three things simultaneously).
Maestro David Craig, your filling will be lousy anyway.
If your x and y arrays come from linespace, you will surely get a 
triangle, and not the curvilinear area between GreatCircles. You must 
transform the coordinates in a more clever (but equally easy...) way.
Jerzy K.
From: Jerzy K. <jer...@un...> - 2012年05月13日 10:14:09
Le 13/05/2012 11:34, David Craig a écrit :
> Hi, I'm having a problem usinf fill_between() with basemap. I plot two 
> great circles and want to shade the region between them. My code is 
> below, it doesnt give any error just creates the plot without filling 
> the area. Does anyone know if it's possible to do this or should I try 
> a different method?
Hello, Boss.
Perhaps I am telling rubbish, but fill_between demands the coordinates 
within your axes, not the basemap angles. Your a,b,c contain some small 
numers (negative x, say -38) won't do any good, x should be, say 3001129 
etc. Use m(...) to convert.
Jerzy K
From: David C. <dcd...@gm...> - 2012年05月13日 09:34:43
Hi, I'm having a problem usinf fill_between() with basemap. I plot two
great circles and want to shade the region between them. My code is below,
it doesnt give any error just creates the plot without filling the area.
Does anyone know if it's possible to do this or should I try a different
method?
Thanks,
David
from mpl_toolkits.basemap import Basemap
from pylab import *
### PARAMETERS FOR MATPLOTLIB :
import matplotlib as mpl
rcParams['font.size'] = 10.
rcParams['font.family'] = 'Comic Sans MS'
rcParams['axes.labelsize'] = 8.
rcParams['xtick.labelsize'] = 6.
rcParams['ytick.labelsize'] = 6.
def shoot(lon, lat, azimuth, maxdist=None):
 """Shooter Function
 Original javascript on http://williams.best.vwh.net/gccalc.htm
 Translated to python by Thomas Lecocq
 """
 glat1 = lat * pi / 180.
 glon1 = lon * pi / 180.
 s = maxdist / 1.852
 faz = azimuth * pi / 180.
 EPS= 0.00000000005
 if ((abs(cos(glat1))<EPS) and not (abs(sin(faz))<EPS)):
 alert("Only N-S courses are meaningful, starting at a pole!")
 a=6378.13/1.852
 f=1/298.257223563
 r = 1 - f
 tu = r * tan(glat1)
 sf = sin(faz)
 cf = cos(faz)
 if (cf==0):
 b=0.
 else:
 b=2. * arctan2 (tu, cf)
 cu = 1. / sqrt(1 + tu * tu)
 su = tu * cu
 sa = cu * sf
 c2a = 1 - sa * sa
 x = 1. + sqrt(1. + c2a * (1. / (r * r) - 1.))
 x = (x - 2.) / x
 c = 1. - x
 c = (x * x / 4. + 1.) / c
 d = (0.375 * x * x - 1.) * x
 tu = s / (r * a * c)
 y = tu
 c = y + 1
 while (abs (y - c) > EPS):
 sy = sin(y)
 cy = cos(y)
 cz = cos(b + y)
 e = 2. * cz * cz - 1.
 c = y
 x = e * cy
 y = e + e - 1.
 y = (((sy * sy * 4. - 3.) * y * cz * d / 6. + x) *
 d / 4. - cz) * sy * d + tu
 b = cu * cy * cf - su * sy
 c = r * sqrt(sa * sa + b * b)
 d = su * cy + cu * sy * cf
 glat2 = (arctan2(d, c) + pi) % (2*pi) - pi
 c = cu * cy - su * sy * cf
 x = arctan2(sy * sf, c)
 c = ((-3. * c2a + 4.) * f + 4.) * c2a * f / 16.
 d = ((e * cy * c + cz) * sy * c + y) * sa
 glon2 = ((glon1 + x - (1. - c) * d * f + pi) % (2*pi)) - pi
 baz = (arctan2(sa, b) + pi) % (2 * pi)
 glon2 *= 180./pi
 glat2 *= 180./pi
 baz *= 180./pi
 return (glon2, glat2, baz)
#Create a basemap around N. Atlantic
m = Basemap(llcrnrlon=-45.0,llcrnrlat=30.0,urcrnrlon=15.0,urcrnrlat=75.0,
 resolution='i',projection='merc',lon_0=-17.5,lat_0=60.0)
m.drawcountries(linewidth=0.5)
m.drawcoastlines(linewidth=0.5)
m.bluemarble()
m.drawparallels(arange(40.,75.,10.),labels=[1,0,0,0],color='black',dashes=[1,0],labelstyle='+/-',linewidth=0.2)
# draw parallels
m.drawmeridians(arange(-45.,15.,10.),labels=[0,0,0,1],color='black',dashes=[1,0],labelstyle='+/-',linewidth=0.2)
# draw meridians
# Shade region defined by great circles.
x1, y1 = -9.1676613, 51.6029999
az1 = 270.
az2 = 290.
maxdist = 2000
x2, y2, baz = shoot(x1, y1, az1, maxdist)
x3, y3, baz = shoot(x1, y1, az2, maxdist)
m.drawgreatcircle(x1, y1, x2, y2, del_s=10, color='gray', lw=1.)
m.drawgreatcircle(x1, y1, x3, y3, del_s=10, color='gray', lw=1.)
a=linspace(x3,x1)
b=linspace(y2,y1)
c=linspace(y3,y1)
fill_between(a, b, c, where=None, alpha=0.2)
show()
From: Jerzy K. <jer...@un...> - 2012年05月13日 09:29:48
(13/05/2012 02:52), Arek Kędzior:
> What I am trying is to plot multiple discontinuous lines.
> I know that this approach does not work very well. How about
> using LineCollection.
> Put all curves into line collection
> Use Pick event to get line segment (what function to use ?)
> Once I have line segment, get xdata, ydata corresponding to line 
> segment (what function to use ?)
Why don't you use:
picker=myTest
in your ax.plot, where
def myTest(artist,mousevnt):
...
return (hit,kwdict)
performs any test you like? Again, this is called separately for every 
Artist belonging to the Usual Suspects, but you may control whether this 
is the first line found, then your program just computes the distance, 
or the second one, then it computes the distance, and discriminates 
between the two. The properties kwdict passed to your callback will 
permit to do the rest.
Or, perhaps, the first time the test doesn't do anything, and returns 
False, and the second time computes both distances, and finds the 
minimum. You have your "private" access to both lines anyway. The 
generalization to many lines should be straightforward.
Jerzy K.
From: Arek K. <ake...@ya...> - 2012年05月13日 00:52:27
What I am trying is to plot multiple discontinuous lines.
I know that this approach does not work very well. How about
using LineCollection.
Put all curves into line collection
Use Pick event to get line segment (what function to use ?)
Once I have line segment, get xdata, ydata corresponding to line segment (what function to use ?)
 
I tied this approach as well
Put all data points into numpy.array and each curve was separated by numpy.nan
It worked but I was getting run-time warning in distance calculations.
Any suggestions how to ?
Regards,
Arek
 
________________________________
 From: "mat...@li..." <mat...@li...>
To: mat...@li... 
Sent: Saturday, May 12, 2012 1:12 PM
Subject: Matplotlib-users Digest, Vol 72, Issue 11
 
Send Matplotlib-users mailing list submissions to
  mat...@li...
To subscribe or unsubscribe via the World Wide Web, visit
  https://lists.sourceforge.net/lists/listinfo/matplotlib-users
or, via email, send a message with subject or body 'help' to
  mat...@li...
You can reach the person managing the list at
  mat...@li...
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Matplotlib-users digest..."
Today's Topics:
 1. Re: Matplotlib-users Digest, Vol 72, Issue 10 (Arek Kedzior)
 2. Re: pick event (Arek Kedzior)
----------------------------------------------------------------------
Message: 1
Date: 2012年5月12日 09:35:59 -0700 (PDT)
From: Arek Kedzior <ake...@ya...>
Subject: Re: [Matplotlib-users] Matplotlib-users Digest, Vol 72, Issue
  10
To: "mat...@li..."
  <mat...@li...>
Message-ID:
  <133...@we...>
Content-Type: text/plain; charset="iso-8859-1"
If you pick one of the curves in the close location to tangancy area, the OnPick function?will be?ececuted twice (2 curves) and will display 2 markers. I want to find the shortest distance from the pick location (mouse coord.) to a discrete point on the curve and?draw?marker on the curve at this location (only one).? See the line with "print lineObj" 
________________________________
From: "mat...@li..." <mat...@li...>
To: mat...@li... 
Sent: Saturday, May 12, 2012 10:59 AM
Subject: Matplotlib-users Digest, Vol 72, Issue 10
 
Send Matplotlib-users mailing list submissions to
??? mat...@li...
To subscribe or unsubscribe via the World Wide Web, visit
??? https://lists.sourceforge.net/lists/listinfo/matplotlib-users
or, via email, send a message with subject or body 'help' to
??? mat...@li...
You can reach the person managing the list at
??? mat...@li...
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Matplotlib-users digest..."
Today's Topics:
? 1. pick event (Arek Kedzior)
? 2. Re: pick event (Jerzy Karczmarczuk)
? 3. Re: pick event (Benjamin Root)
----------------------------------------------------------------------
Message: 1
Date: 2012年5月12日 06:07:37 -0700 (PDT)
From: Arek Kedzior <ake...@ya...>
Subject: [Matplotlib-users] pick event
To: "mat...@li..."
??? <mat...@li...>
Message-ID:
??? <133...@we...>
Content-Type: text/plain; charset="iso-8859-1"
I am trying to use pick event.? See the simple script
below.? I am interested to find the shortest distance between pick
point (mouse coord.) and the ?line at the discrete points only (points on
the curve from data)
What am I doing wrong ?
Regards,
Arek
?
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
import math as math
?
# create figure and attach axes to it
fig = plt.figure(1)
ax = fig.add_subplot(111)
?
?
def getMinDistance(xmouse, ymouse, xList, yList):
??? """
??? find shortest distance between mouse
coordinates and pick point
??? point pick may be a list of points if
data is clouded
??? Input
??? xmouse - x coordinate of mouse (x - pick)
??? ymouse - y coordinate of mouse (y - pick)
??? xList? - xData from curve
??? yList? - yData from curve
??? Returns:
??? dmin? - minimum distance
??? index - index of data point in the xList
and yList
??? """
????dmin? = math.sqrt((xList[0] -
xmouse)**2. + (yList[0]-ymouse)**2.)? 
????index = 0
??? for idx in range(1,len(xList)):
??????? d =
math.sqrt((xList[idx] - xmouse)**2. + (yList[idx]-ymouse)**2.)
??????? if(d < dmin):
???????????
dmin = d
???????????
index = idx
????return dmin, index
?
def showMarker(x, y, color):
??? """
??? draw marker at loction x, y with color
??? """
??? # draw marker
??? markerOn, = ax.plot(x, y, 'o', color =
color) 
????
def OnPick(event):
??? """
??? pick event
??? """
??? print '****************************'
??? mouseEvent = event.mouseevent
??? # get pick coord
??? xmouse, ymouse = mouseEvent.xdata,
mouseEvent.ydata
??? # get the artist
??? lineObj = event.artist 
????print lineObj
????if not isinstance(lineObj, Line2D):
??????? return 
????ind = event.ind 
????# check if indexes exist of the pick
object
??? N = len(ind)
??? if not N:
??????? return
??? # get curve picked data
??? Xdata, Ydata = lineObj.get_data()
??? color = lineObj.get_color()
????xLi = np.take(Xdata, ind)
??? yLi = np.take(Ydata, ind)
??? dmin, index = getMinDistance(xmouse,
ymouse, xLi, yLi)
??? 
????xP = xLi[index]
??? yP = yLi[index]
??? 
????xStr = '%.4g' % xP
??? yStr = '%.4g' % yP
??? txt = 'X = ' + xStr + ' ;? ' + 'Y =
' + yStr
??? print txt
??? # show marker
??? showMarker(xP, yP, color)
??? # redraw to show marker
??? fig.canvas.draw()
??? 
# connect to pick event??? 
fig.canvas.mpl_connect('pick_event',OnPick)
?
# generate data for display
x = np.arange(-4,4,0.1)????? # x-
coord
y2 = x**2 + 5.0?????????????
# y coord of first curve
y? = 2*x +
4.0??????????????
# y coord of the second curve
# create the list of x and y data 
xList = [x,
x]?????????????? 
yList = [y, y2]
objList = []???? # store draw lines
(artists)
# display 2 curves 
for idx in range(len(xList)):
??? obj, = ax.plot(xList[idx], yList[idx],
picker = 5)
??? objList.append(obj)
?
# display plot
plt.show(1)
-------------- next part --------------
An HTML attachment was scrubbed...
------------------------------
Message: 2
Date: 2012年5月12日 16:44:16 +0200
From: Jerzy Karczmarczuk <jer...@un...>
Subject: Re: [Matplotlib-users] pick event
To: mat...@li...
Message-ID: <4FA...@un...>
Content-Type: text/plain; charset="iso-8859-1"
Arek Ke;dzior:
> I am trying to use pick event.
...
> What am I doing wrong ?
Wrong with WHAT?
What do you expect?
Jerzy Karczmarczuk
-------------- next part --------------
An HTML attachment was scrubbed...
------------------------------
Message: 3
Date: 2012年5月12日 10:59:39 -0400
From: Benjamin Root <ben...@ou...>
Subject: Re: [Matplotlib-users] pick event
To: "jer...@un..." <jer...@un...>
Cc: "mat...@li..."
??? <mat...@li...>
Message-ID:
??? <CANNq6FnEP7Ugwvfj5FmVAyqsqyzhcc4bZg95J1Gzf_sq=2h...@ma...>
Content-Type: text/plain; charset="utf-8"
On Saturday, May 12, 2012, Jerzy Karczmarczuk wrote:
>? Arek K?dzior:
>
>? I am trying to use pick event.
>
> ...
>
>? What am I doing wrong ?
>
> Wrong with WHAT?
> What do you expect?
>
> Jerzy Karczmarczuk
>
Arek.
Could you provide a little more detail about your issue?
Cheers!
Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
------------------------------
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
------------------------------
_______________________________________________
Matplotlib-users mailing list
Mat...@li...
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
End of Matplotlib-users Digest, Vol 72, Issue 10
************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
------------------------------
Message: 2
Date: 2012年5月12日 10:12:18 -0700 (PDT)
From: Arek Kedzior <ake...@ya...>
Subject: Re: [Matplotlib-users] pick event
To: "mat...@li..."
  <mat...@li...>
Message-ID:
  <133...@we...>
Content-Type: text/plain; charset="iso-8859-1"
If you pick one of the curves in the close location to tangancy area, the OnPick function will be ececuted twice (2 curves) and will display 2 markers. I want to find the shortest distance from the pick location (mouse coord.) to a discrete point on the curve and draw marker on the curve at this location (only one). See the line with "print lineObj" 
________________________________
From: "mat...@li..." <mat...@li...>
To: mat...@li... 
Sent: Saturday, May 12, 2012 10:59 AM
Subject: Matplotlib-users Digest, Vol 72, Issue 10
 
Send Matplotlib-users mailing list submissions to
??? mat...@li...
To subscribe or unsubscribe via the World Wide Web, visit
??? https://lists.sourceforge.net/lists/listinfo/matplotlib-users
or, via email, send a message with subject or body 'help' to
??? mat...@li...
You can reach the person managing the list at
??? mat...@li...
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Matplotlib-users digest..."
Today's Topics:
? 1. pick event (Arek Kedzior)
? 2. Re: pick event (Jerzy Karczmarczuk)
? 3. Re: pick event (Benjamin Root)
----------------------------------------------------------------------
Message: 1
Date: 2012年5月12日 06:07:37 -0700 (PDT)
From: Arek Kedzior <ake...@ya...>
Subject: [Matplotlib-users] pick event
To: "mat...@li..."
??? <mat...@li...>
Message-ID:
??? <133...@we...>
Content-Type: text/plain; charset="iso-8859-1"
I am trying to use pick event.? See the simple script
below.? I am interested to find the shortest distance between pick
point (mouse coord.) and the ?line at the discrete points only (points on
the curve from data)
What am I doing wrong ?
Regards,
Arek
?
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
import math as math
?
# create figure and attach axes to it
fig = plt.figure(1)
ax = fig.add_subplot(111)
?
?
def getMinDistance(xmouse, ymouse, xList, yList):
??? """
??? find shortest distance between mouse
coordinates and pick point
??? point pick may be a list of points if
data is clouded
??? Input
??? xmouse - x coordinate of mouse (x - pick)
??? ymouse - y coordinate of mouse (y - pick)
??? xList? - xData from curve
??? yList? - yData from curve
??? Returns:
??? dmin? - minimum distance
??? index - index of data point in the xList
and yList
??? """
????dmin? = math.sqrt((xList[0] -
xmouse)**2. + (yList[0]-ymouse)**2.)? 
????index = 0
??? for idx in range(1,len(xList)):
??????? d =
math.sqrt((xList[idx] - xmouse)**2. + (yList[idx]-ymouse)**2.)
??????? if(d < dmin):
???????????
dmin = d
???????????
index = idx
????return dmin, index
?
def showMarker(x, y, color):
??? """
??? draw marker at loction x, y with color
??? """
??? # draw marker
??? markerOn, = ax.plot(x, y, 'o', color =
color) 
????
def OnPick(event):
??? """
??? pick event
??? """
??? print '****************************'
??? mouseEvent = event.mouseevent
??? # get pick coord
??? xmouse, ymouse = mouseEvent.xdata,
mouseEvent.ydata
??? # get the artist
??? lineObj = event.artist 
????print lineObj
????if not isinstance(lineObj, Line2D):
??????? return 
????ind = event.ind 
????# check if indexes exist of the pick
object
??? N = len(ind)
??? if not N:
??????? return
??? # get curve picked data
??? Xdata, Ydata = lineObj.get_data()
??? color = lineObj.get_color()
????xLi = np.take(Xdata, ind)
??? yLi = np.take(Ydata, ind)
??? dmin, index = getMinDistance(xmouse,
ymouse, xLi, yLi)
??? 
????xP = xLi[index]
??? yP = yLi[index]
??? 
????xStr = '%.4g' % xP
??? yStr = '%.4g' % yP
??? txt = 'X = ' + xStr + ' ;? ' + 'Y =
' + yStr
??? print txt
??? # show marker
??? showMarker(xP, yP, color)
??? # redraw to show marker
??? fig.canvas.draw()
??? 
# connect to pick event??? 
fig.canvas.mpl_connect('pick_event',OnPick)
?
# generate data for display
x = np.arange(-4,4,0.1)????? # x-
coord
y2 = x**2 + 5.0?????????????
# y coord of first curve
y? = 2*x +
4.0??????????????
# y coord of the second curve
# create the list of x and y data 
xList = [x,
x]?????????????? 
yList = [y, y2]
objList = []???? # store draw lines
(artists)
# display 2 curves 
for idx in range(len(xList)):
??? obj, = ax.plot(xList[idx], yList[idx],
picker = 5)
??? objList.append(obj)
?
# display plot
plt.show(1)
-------------- next part --------------
An HTML attachment was scrubbed...
------------------------------
Message: 2
Date: 2012年5月12日 16:44:16 +0200
From: Jerzy Karczmarczuk <jer...@un...>
Subject: Re: [Matplotlib-users] pick event
To: mat...@li...
Message-ID: <4FA...@un...>
Content-Type: text/plain; charset="iso-8859-1"
Arek Ke;dzior:
> I am trying to use pick event.
...
> What am I doing wrong ?
Wrong with WHAT?
What do you expect?
Jerzy Karczmarczuk
-------------- next part --------------
An HTML attachment was scrubbed...
------------------------------
Message: 3
Date: 2012年5月12日 10:59:39 -0400
From: Benjamin Root <ben...@ou...>
Subject: Re: [Matplotlib-users] pick event
To: "jer...@un..." <jer...@un...>
Cc: "mat...@li..."
??? <mat...@li...>
Message-ID:
??? <CANNq6FnEP7Ugwvfj5FmVAyqsqyzhcc4bZg95J1Gzf_sq=2h...@ma...>
Content-Type: text/plain; charset="utf-8"
On Saturday, May 12, 2012, Jerzy Karczmarczuk wrote:
>? Arek K?dzior:
>
>? I am trying to use pick event.
>
> ...
>
>? What am I doing wrong ?
>
> Wrong with WHAT?
> What do you expect?
>
> Jerzy Karczmarczuk
>
Arek.
Could you provide a little more detail about your issue?
Cheers!
Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
------------------------------
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
------------------------------
_______________________________________________
Matplotlib-users mailing list
Mat...@li...
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
End of Matplotlib-users Digest, Vol 72, Issue 10
************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
------------------------------
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
------------------------------
_______________________________________________
Matplotlib-users mailing list
Mat...@li...
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
End of Matplotlib-users Digest, Vol 72, Issue 11
************************************************

Showing 6 results of 6

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /