2014-09-05 26 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