Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dee0f95

Browse files
committed
Merged revisions 8717-8718,8720 via svnmerge from
https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/branches/v1_0_maint ........ r8717 | jdh2358 | 2010-09-24 04:54:34 +0900 (Fri, 24 Sep 2010) | 1 line added citation faq ........ r8718 | jdh2358 | 2010-09-24 05:07:12 +0900 (Fri, 24 Sep 2010) | 1 line wrap the mpl citation abstract ........ r8720 | leejjoon | 2010-09-27 10:30:19 +0900 (Mon, 27 Sep 2010) | 1 line fix bezier.get_parallerls to handle parallel input lines ........ svn path=/trunk/matplotlib/; revision=8721
1 parent de74e56 commit dee0f95

2 files changed

Lines changed: 73 additions & 8 deletions

File tree

doc/faq/howto_faq.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,4 +731,34 @@ ellipse, :ref:`search` for ``codex ellipse``.
731731

732732

733733

734+
.. _how-to-cite-mpl:
735+
736+
Cite Matplotlib
737+
=================
738+
739+
If you want to refer to matplotlib in a publication, you can use
740+
"Matplotlib: A 2D Graphics Environment" by J. D. Hunter In Computing in Science &
741+
Engineering, Vol. 9, No. 3. (2007), pp. 90-95 (see `citeulike <http://www.citeulike.org/user/jabl/article/2878517>`_)::
742+
743+
@article{Hunter:2007,
744+
Address = {10662 LOS VAQUEROS CIRCLE, PO BOX 3014, LOS ALAMITOS, CA 90720-1314 USA},
745+
Author = {Hunter, John D.},
746+
Date-Added = {2010-09-23 12:22:10 -0700},
747+
Date-Modified = {2010-09-23 12:22:10 -0700},
748+
Isi = {000245668100019},
749+
Isi-Recid = {155389429},
750+
Journal = {Computing In Science \& Engineering},
751+
Month = {May-Jun},
752+
Number = {3},
753+
Pages = {90--95},
754+
Publisher = {IEEE COMPUTER SOC},
755+
Times-Cited = {21},
756+
Title = {Matplotlib: A 2D graphics environment},
757+
Type = {Editorial Material},
758+
Volume = {9},
759+
Year = {2007},
760+
Abstract = {Matplotlib is a 2D graphics package used for Python for application
761+
development, interactive scripting, and publication-quality image
762+
generation across user interfaces and operating systems.},
763+
Bdsk-Url-1 = {http://gateway.isiknowledge.com/gateway/Gateway.cgi?GWVersion=2&SrcAuth=Alerting&SrcApp=Alerting&DestApp=WOS&DestLinkType=FullRecord;KeyUT=000245668100019}}
734764

lib/matplotlib/bezier.py

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from matplotlib.path import Path
1010

1111
from operator import xor
12+
import warnings
1213

1314

1415
# some functions
@@ -323,6 +324,22 @@ def get_cos_sin(x0, y0, x1, y1):
323324
d = (dx*dx + dy*dy)**.5
324325
return dx/d, dy/d
325326

327+
def check_if_parallel(dx1, dy1, dx2, dy2, tolerence=1.e-5):
328+
""" returns
329+
* 1 if two lines are parralel in same direction
330+
* -1 if two lines are parralel in opposite direction
331+
* 0 otherwise
332+
"""
333+
theta1 = np.arctan2(dx1, dy1)
334+
theta2 = np.arctan2(dx2, dy2)
335+
dtheta = np.abs(theta1 - theta2)
336+
if dtheta < tolerence:
337+
return 1
338+
elif np.abs(dtheta - np.pi) < tolerence:
339+
return -1
340+
else:
341+
return False
342+
326343

327344
def get_parallels(bezier2, width):
328345
"""
@@ -338,10 +355,18 @@ def get_parallels(bezier2, width):
338355
cmx, cmy = bezier2[1]
339356
c2x, c2y = bezier2[2]
340357

341-
# t1 and t2 is the anlge between c1 and cm, cm, c2.
342-
# They are also a angle of the tangential line of the path at c1 and c2
343-
cos_t1, sin_t1 = get_cos_sin(c1x, c1y, cmx, cmy)
344-
cos_t2, sin_t2 = get_cos_sin(cmx, cmy, c2x, c2y)
358+
parallel_test = check_if_parallel(c1x-cmx, c1y-cmy, cmx-c2x, cmy-c2y)
359+
360+
if parallel_test == -1:
361+
warnings.warn("Lines do not intersect. A straight line is used instead.")
362+
#cmx, cmy = 0.5*(c1x+c2x), 0.5*(c1y+c2y)
363+
cos_t1, sin_t1 = get_cos_sin(c1x, c1y, c2x, c2y)
364+
cos_t2, sin_t2 = cos_t1, sin_t1
365+
else:
366+
# t1 and t2 is the anlge between c1 and cm, cm, c2. They are
367+
# also a angle of the tangential line of the path at c1 and c2
368+
cos_t1, sin_t1 = get_cos_sin(c1x, c1y, cmx, cmy)
369+
cos_t2, sin_t2 = get_cos_sin(cmx, cmy, c2x, c2y)
345370

346371
# find c1_left, c1_right which are located along the lines
347372
# throught c1 and perpendicular to the tangential lines of the
@@ -355,11 +380,21 @@ def get_parallels(bezier2, width):
355380
# find cm_left which is the intersectng point of a line through
356381
# c1_left with angle t1 and a line throught c2_left with angle
357382
# t2. Same with cm_right.
358-
cmx_left, cmy_left = get_intersection(c1x_left, c1y_left, cos_t1, sin_t1,
359-
c2x_left, c2y_left, cos_t2, sin_t2)
383+
if parallel_test != 0:
384+
# a special case for a straight line, i.e., angle between two
385+
# lines are smaller than some (arbitrtay) value.
386+
cmx_left, cmy_left = \
387+
0.5*(c1x_left+c2x_left), 0.5*(c1y_left+c2y_left)
388+
cmx_right, cmy_right = \
389+
0.5*(c1x_right+c2x_right), 0.5*(c1y_right+c2y_right)
390+
else:
391+
cmx_left, cmy_left = \
392+
get_intersection(c1x_left, c1y_left, cos_t1, sin_t1,
393+
c2x_left, c2y_left, cos_t2, sin_t2)
360394

361-
cmx_right, cmy_right = get_intersection(c1x_right, c1y_right, cos_t1, sin_t1,
362-
c2x_right, c2y_right, cos_t2, sin_t2)
395+
cmx_right, cmy_right = \
396+
get_intersection(c1x_right, c1y_right, cos_t1, sin_t1,
397+
c2x_right, c2y_right, cos_t2, sin_t2)
363398

364399
# the parralel bezier lines are created with control points of
365400
# [c1_left, cm_left, c2_left] and [c1_right, cm_right, c2_right]

0 commit comments

Comments
 (0)