2014-09-05 97 views
1

更改Matplotlib矩形金環考慮下面的代碼繪製:在聯想

plt.figure(figsize=(10,6)) 
for k in range(nruns): 
    plt.plot(Thing1['Data'][:,k],color='Grey',alpha=0.10) 
plt.plot(Thing2[:,1],Thing2[:,4],'ko') 
a = plt.Rectangle((0, 0), 1, 1, fc="Grey",alpha=0.50) 
b = plt.Rectangle((0, 0), 1, 1, fc="Black", alpha=1.00) 
plt.legend([a,b], ["Thing1","Thing2"],loc=2,fontsize='small') 
plt.xlabel("Time",fontsize=16) 
plt.ylabel("Hijinks",fontsize=16) 
plt.show() 

我真的很喜歡「B」是一個圓圈,而不是一個矩形。但是我對matplotlib代碼感到非常可怕,特別是代理藝術家的使用。有沒有一種簡單的方法可以做到這一點?

回答

0

你非常接近。你只需要使用一個Line2D藝術家,並設置其屬性,如ususal:

import matplotlib.pyplot as plt 

fig, ax = plt.subplots(figsize=(10,6)) 

fakexy = (0, 0) 
a = plt.Rectangle(fakexy, 1, 1, fc="Grey",alpha=0.50) 
b = plt.Line2D(fakexy, fakexy, linestyle='none', marker='o', markerfacecolor="Black", alpha=1.00) 

ax.legend([a, b], ["Thing1", "Thing2"], loc='upper left', fontsize='small') 
ax.set_xlabel("Time", fontsize=16) 
ax.set_ylabel("Hijinks", fontsize=16) 

我得到:

enter image description here