2017-02-16 10 views
2

matplotlibにLineCollectionを使用して、多数のラインをすばやく異なる色でプロットしています。しかし、LineCollectionのドキュメントを見ても、ラインのラインマーカーを設定する方法が見つかりません。 LineCollectionを使用するときにラインマーカーを使用する方法はありますか?LineCollectionを使用するときにラインマーカーを追加する

注:pyplot.plot()を使用するのは、使用例が遅すぎるため、約200k行をプロットするオプションではありません。

イラスト例: enter image description here

コード例(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() 

答えて

2

私はあなたがLineCollectionにマーカーを追加することができないと思います。しかし、あなたのLineCollectionの上にあなたのマーカーをプロットするax.scatterを使用すると、おそらく、例えばax.plot

を使用するよりも速くなり、何かのように:

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

関連する問題