2012-05-13 13 views
12

Aşağıdaki kodda, her iki scatter grafiğini (yani yeşil daireyi sarı ok başlığına bağlayan) birbirine bağlayan iki kod çizgisi ile oluşturulan satırları nasıl oluşturabilirim? .show() komutundan hemen önce mi?Python ve matplotlib'de bir 3B dağılım grafiğinde iki noktayı bağlama

import matplotlib.pyplot 
from mpl_toolkits.mplot3d import Axes3D 

dates  = [20020514, 20020515, 20020516, 20020517, 20020520] 
highs  = [1135, 1158, 1152, 1158, 1163] 
lows  = [1257, 1253, 1259, 1264, 1252] 
upperLimits = [1125.0, 1125.0, 1093.75, 1125.0, 1125.0] 
lowerLimits = [1250.0, 1250.0, 1156.25, 1250.0, 1250.0] 

zaxisvalues0= [0, 0, 0, 0, 0] 
zaxisvalues1= [1, 1, 1, 1, 1] 
zaxisvalues2= [2, 2, 2, 2, 2] 

fig = matplotlib.pyplot.figure() 
ax = fig.add_subplot(111, projection = '3d') 

ax.plot(dates, zaxisvalues1, lowerLimits, color = 'b') 
ax.plot(dates, zaxisvalues2, upperLimits, color = 'r') 

ax.scatter(dates, zaxisvalues0, highs, color = 'g', marker = "o") 
ax.scatter(dates, zaxisvalues0, lows, color = 'y', marker = "^") 

matplotlib.pyplot.show() 

cevap

17

bu noktalar arasındaki bir çizgi segmenti çiz:

import matplotlib.pyplot 
from mpl_toolkits.mplot3d import Axes3D 

dates  = [20020514, 20020515, 20020516, 20020517, 20020520] 
highs  = [1135, 1158, 1152, 1158, 1163] 
lows  = [1257, 1253, 1259, 1264, 1252] 
upperLimits = [1125.0, 1125.0, 1093.75, 1125.0, 1125.0] 
lowerLimits = [1250.0, 1250.0, 1156.25, 1250.0, 1250.0] 

zaxisvalues0= [0, 0, 0, 0, 0] 
zaxisvalues1= [1, 1, 1, 1, 1] 
zaxisvalues2= [2, 2, 2, 2, 2] 

fig = matplotlib.pyplot.figure() 
ax = fig.add_subplot(111, projection = '3d') 

ax.plot(dates, zaxisvalues1, lowerLimits, color = 'b') 
ax.plot(dates, zaxisvalues2, upperLimits, color = 'r') 

for i,j,k,h in zip(dates,zaxisvalues0,lows,highs): 
    ax.plot([i,i],[j,j],[k,h],color = 'g') 

ax.scatter(dates, zaxisvalues0, highs, color = 'g', marker = "o") 
ax.scatter(dates, zaxisvalues0, lows, color = 'y', marker = "^") 

matplotlib.pyplot.show() 

üretir:

enter image description here

+0

Süper! Sağol Mark. Bireysel noktaları (bir dizi ya da listedeki bir dizi yerine) istediği zaman çizebileceğimi asla fark etmemiştim. Şimdi bir satır yerine bir dikdörtgen çizmek istesem ne olur? "For" döngüsünde "ax.plot" 'u "ax.bar" olarak değiştirmeyi denedim ama bunun yerine eğri çizgiler aldım. Bir dikdörtgen çizmenin bir yolu var mı? Şimdiden teşekkürler. – Zambi

+3

@Zambi Stackoverflow'a Hoş Geldiniz! Ekstra sorulara dokunmak yerine, bir _new_ sorusu sormak daha mantıklı. – Hooked

+0

Zambi, @Hooked'ın söylediği gibi, daha büyük bir topluluğun görebilmesi için yeni bir soru açmak en iyisidir. Hızlı bir görünüm olsa da, iki seçeneğiniz var, dikdörtgenin 4 tarafını "çizim" çizgileriyle çizin veya PolyCollection'ı kullanarak inceleyin (http://matplotlib.sourceforge.net/examples/mplot3d/polys3d_demo.html) – Mark

İlgili konular