[SciPy-User] inserting nan at a point in two arrays
David Pine
djpine at gmail.com
Tue Jul 20 13:28:24 EDT 2010
Paul,
Marvelous! Thanks. That does the trick.
Dave
On Jul 21, 2010, at 12:10 AM, <PHobson at Geosyntec.com> wrote:
>> -----Original Message-----
>> From: scipy-user-bounces at scipy.org [mailto:scipy-user-bounces at scipy.org]
>> On Behalf Of David Pine
>> Sent: Tuesday, July 20, 2010 5:08 AM
>> To: scipy-user at scipy.org
>> Subject: [SciPy-User] inserting nan at a point in two arrays
>>
>> I want to plot tan(x) vs x with a gap in the line plot when x goes
>> thought pi/2, the point where tan(x) goes from +infinity to -infinity.
>> The idea is to insert nan between the points in the tan(x) and x arrays
>> at x=pi/2, which will leave the desired gap when plot is called. Does
>> anyone have an efficient way to do this?
>
> Simplest thing to do would be to set a threshold (10,000?) and use a masked array.
>
> # code ---
> import numpy as np
> import matplotlib.pyplot as plt
>
> threshold = 1e5
> x = np.arange(0, 2*np.pi, np.pi/16)
> y = np.tan(x)
> ym = np.ma.MaskedArray(y, np.abs(y) > threshold)
>
> fig = plt.figure()
> ax1 = fig.add_subplot(1,1,1)
> ax1.plot(x, ym, 'k-')
> ax1.set_xlabel('Radians')
> ax1.set_ylabel('Masked Tangent Function')
> # ---/code
>
> Hope that help
> -paul
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
More information about the SciPy-User
mailing list