2017-02-16 3 views
2

Ich verwende in Matplotlib, um eine große Anzahl von Linien schnell und mit verschiedenen Farben zu plotten. Ich kann jedoch keine Möglichkeit finden, eine Linienmarkierung für die Linien festzulegen, selbst wenn Sie sich die LineCollection-Dokumentation angesehen haben. Gibt es eine Möglichkeit, Linienmarkierungen zu verwenden, wenn Sie LineCollection verwenden?Hinzufügen von Linienmarkierungen bei Verwendung von LineCollection

Hinweis: Die Verwendung von pyplot.plot() ist keine Option, da sie für meinen Anwendungsfall, der etwa 200.000 Zeilen umfasst, zu langsam ist.

Illustrated Beispiel: enter image description here

-Code verwendet Beispiel zu erzeugen (original source):

import matplotlib.pyplot as plt 
from matplotlib.collections import LineCollection 

lines = [[(0, 1), (1, 1)], [(2, 3), (3, 3)], [(1, 2), (1, 3)]] 

lc = LineCollection(lines, colors=['r', 'g', 'b']) 
fig = plt.figure() 

ax1 = fig.add_subplot(1, 2, 1) 
ax1.add_collection(lc) 
ax1.autoscale() 
ax1.set_title('Current') 

# Doesn't seem to do anything 
for l in ax1.lines: 
    l.set_marker('o') 

ax2 = fig.add_subplot(1, 2, 2) 
ax2.plot([0, 1], [1, 1], 'ro-') 
ax2.plot([2, 3], [3, 3], 'go-') 
ax2.plot([1, 1], [2, 3], 'bo-') 
ax2.set_title('Goal') 

plt.show() 

Antwort

2

Ich glaube nicht, Sie Marker zu einem LineCollection hinzufügen können. Jedoch Ihre Markierungen auf Ihrem LineCollectionax.scatter mit wahrscheinlich wäre schneller zu planen als ax.plot

Zum Beispiel verwenden, so etwas wie:

import matplotlib.pyplot as plt 
from matplotlib.collections import LineCollection 

lines = [[(0, 1), (1, 1)], [(2, 3), (3, 3)], [(1, 2), (1, 3)]] 
colors = ['r', 'g', 'b'] 

lc = LineCollection(lines, colors=['r', 'g', 'b']) 
fig = plt.figure() 

ax1 = fig.add_subplot(1, 1, 1) 
ax1.add_collection(lc) 
ax1.autoscale() 

x = [i[0] for j in lines for i in j] 
y = [i[1] for j in lines for i in j] 
c = [col for col in colors for _ in (0, 1)] 

ax1.scatter(x, y, c=c) 

plt.show() 

enter image description here

Verwandte Themen