[Matplotlib-users] Add disconnected lines to a plot

Juan Nunez-Iglesias jni at fastmail.com
Mon May 4 08:25:47 EDT 2020


An alternative approach to inserting nans is to use a LineCollection. I have some sample code using it here:

https://github.com/jni/skan/blob/master/skan/draw.py#L133-L146

But the documentation is quite clear:

https://matplotlib.org/3.1.1/api/collections_api.html#matplotlib.collections.LineCollection

See specifically the description of `segments`, which can be either an array of shape (n_segments, n_points, 2), ie (n, 2, 2) in your case, or a list of line segments.

Juan.

On Mon, 4 May 2020, at 4:00 AM, Jerzy Karczmarczuk wrote:
> On 04/05/2020 8:30 am, EK Esawi via Matplotlib-users wrote:

>> i am trying to use lists instead of numpy plus, it's been a while since i programmed in Python.
> Some advice...

> 1. People who too often complain that they are beginners, are likely to remain beginners forever. Beware.

> 2. If you expect to use matplotlib (or plotly, or pyqtgraph, etc.) frequently, master Numpy, or sooner than you think, you will suffer very, very much.

> 3. My previous example was loop-less; this is one of many advantages of Numpy. But you can do it in the orthodox way as well.

> 

> *from random import random as rn
>  import matplotlib.pyplot as plt
>  n=20
>  nan=float('nan')
>  a=[rn() for k in range(n)] # just a silly random example
> 
>  for j in range(n-2,0,-2):
> a.insert(j,nan)# insert your Nans in such a way
>  plt.plot(a) *

> 

> Best regards


> Jerzy Karczmarczuk
>  /Caen, France/

> 

> 

> 
> 
> 
> Avast logo  <https://www.avast.com/antivirus>

> This email has been checked for viruses by Avast antivirus software. 
> www.avast.com <https://www.avast.com/antivirus>

> 
 <https://www.fastmail.com/mail/compose/Mbf1dac787a3cb57933a43590?u=3e3940b1#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
> 
> 
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20200504/5b7894f2/attachment-0001.html>


More information about the Matplotlib-users mailing list