Skip to content Skip to sidebar Skip to footer

Labeled Intervals In Matplotlib

I'm making a reference to the question on Plotting labeled intervals in matplotlib/gnuplot, the problem with the solution exposed there, is that doesn't work with only one line of

Solution 1:

The issue is that when you only read 1 item with np.genfromtxt, it is producing scalars (0-dimensions). We need them to be at least 1D.

You can add these lines just above where you define your timelines function, and then everything works ok.

This makes use of the numpy function np.atleast_1d(), to turn the scalars into 1D numpy arrays.

#Check the dimensions are at least 1D (for 1-item data input)ifstart.ndim<1:start=np.atleast_1d(start)ifstop.ndim<1::stop=np.atleast_1d(stop)ifis_ok.ndim<1:is_ok=np.atleast_1d(is_ok)ifnot_ok.ndim<1:not_ok=np.atleast_1d(is_ok)

The output:

enter image description here

Post a Comment for "Labeled Intervals In Matplotlib"