Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suggestions to plot overlapping lines in matplotlib?

Does anybody have a suggestion on what's the best way to present overlapping lines on a plot? I have a lot of them, and I had the idea of having full lines of different colors where they don't overlap, and having dashed lines where they do overlap so that all colors are visible and overlapping colors are seen.

But still, how do I that.

like image 614
coffeecup Avatar asked Nov 23 '16 14:11

coffeecup


People also ask

How do you avoid overlapping plots in python?

Dot Size. You can try to decrease marker size in your plot. This way they won't overlap and the patterns will be clearer.

How do I stop Matplotlib overlapping?

Use legend() method to avoid overlapping of labels and autopct. To display the figure, use show() method.

How do you overlap a plot?

Double-click on the plot to open the Plot Details dialog, go to the Pattern tab in Plot Details, and set the Transparency control to 51%. Select the Spacing tab, and set Gas Between Bars to zero and Overlap to 100.


2 Answers

Just decrease the opacity of the lines so that they are see-through. You can achieve that using the alpha variable. Example:

plt.plot(x, y, alpha=0.7)

Where alpha ranging from 0-1, with 0 being invisible.

like image 163
Taufiq Rahman Avatar answered Sep 18 '22 05:09

Taufiq Rahman


I have the same issue on a plot with a high degree of discretization.

Here the starting situation:

import matplotlib.pyplot as plt grid=[x for x in range(10)] graphs=[         [1,1,1,4,4,4,3,5,6,0],         [1,1,1,5,5,5,3,5,6,0],         [1,1,1,0,0,3,3,2,4,0],         [1,2,4,4,3,2,3,2,4,0],         [1,2,3,3,4,4,3,2,6,0],         [1,1,3,3,0,3,3,5,4,3],         ]  for gg,graph in enumerate(graphs):     plt.plot(grid,graph,label='g'+str(gg))  plt.legend(loc=3,bbox_to_anchor=(1,0)) plt.show() 

No one can say where the green and blue lines run exactly

and my "solution"

import matplotlib.pyplot as plt grid=[x for x in range(10)] graphs=[         [1,1,1,4,4,4,3,5,6,0],         [1,1,1,5,5,5,3,5,6,0],         [1,1,1,0,0,3,3,2,4,0],         [1,2,4,4,3,2,3,2,4,0],         [1,2,3,3,4,4,3,2,6,0],         [1,1,3,3,0,3,3,5,4,3],         ]  for gg,graph in enumerate(graphs):     lw=10-8*gg/len(graphs)     ls=['-','--','-.',':'][gg%4]     plt.plot(grid,graph,label='g'+str(gg), linestyle=ls, linewidth=lw)  plt.legend(loc=3,bbox_to_anchor=(1,0)) plt.show() 

I am grateful for suggestions on improvement!

like image 32
Markus Dutschke Avatar answered Sep 21 '22 05:09

Markus Dutschke