[SciPy-User] inserting nan at a point in two arrays
Tue Jul 20 12:28:24 CDT 2010
Marvelous! Thanks. That does the trick.
On Jul 21, 2010, at 12:10 AM, <PHobson@Geosyntec.com> wrote:
>> -----Original Message-----
>> From: email@example.com [mailto:firstname.lastname@example.org]
>> On Behalf Of David Pine
>> Sent: Tuesday, July 20, 2010 5:08 AM
>> To: email@example.com
>> 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_ylabel('Masked Tangent Function')
> # ---/code
> Hope that help
> SciPy-User mailing list
More information about the SciPy-User