Wednesday, 15 August 2012

python - Put a gap/break in a line plot -


I sometimes have data sets with "continuous" sensor readings with intervals.

Though there have been no data entered in many periods. This interval is significantly higher than the sample period.

By default, the pipette connects every data point on the next (if I have a line style set), but I think it's a little misleading, when it connects two Figures point to both sides of a long interval.

I just do not want any line there; That is, I want to stop and start the line to start again after the interval.

I have tried to add an element with the y-value none in these intersections, but it seems that this line has been sent back to the first part of the conspiracy (Although weirdly, these lines do not appear at all zoom levels).

The second option which I thought is just a separate call to each piece on the plot , but it would be a bit ugly and cumbersome.

Is there any more attractive way to achieve this?

EDIT: A minimal work example of displaying behavior is the line involved in the first conspiracy that I am trying to avoid. The second plot shows that adding any any value appears to work, although if you pan the view of the plot, then whatever you have been shown in the third shape, He jumps a line in the first part of a plot. NMP import as import import matplotlib.pyplot plt t1 = np.arange (0, 8, 0.05) t2 = np.arange (10, 14, 0.05) T = np.concatenate Import as ([T1, T2]) C = NP COOS (T) fig = PLT.figer () ax = fig.gca () ax. (T, C) ax.Asset_Hrs ('undesirable connecting line') T1 = NP. Ranges (0, 8, 0.05) T2 = N.P. Ranges (10, 14, 0.05) C1 = NP COO (T1 ) C2 = NP COOS (T2) T = N.P.Connetatat ([T1, T1 [-1]:], T2]) c = np.concatenate ([c1, [none,], c2]) Fig = plt.figure () ax = fig.gca () ax.plot (t, c) ax.set_title ('OK if you do not pan the plot') fig = plt.figure () ax = fig.gca () Ax.plot (t, c) ax.axis ([- 1, 12, -0.5, 1.25]) Ax.set_title ('strange jumping line') plt.show () < P> plot3,

The masked arrays work well for this to make you mask those points Required ones you do not want to connect to:

  Import NMP as import Import as numpy.ma import matplotlib.pyplot plt t1 = np.arange (0, 8, 0.05) mask_start = len (t1) t2 = np.arange (10, 14, 0.05) t = np.concatenate ([t1, t2]) c = np.cos (t) # On one side, but this list compares compos Better to use numpy ufuncs in mc = ma.array (c) mc [mask_start] = ma.mask Ed plt.figure () plt.plot (t, mc) plt.title ('use of mask arrays') plt.show ()   

 Enter image details here

At least on my system (OSX, Python 2.7, mpl 1.1.0), I have a panning There is no problem with etc.

No comments:

Post a Comment