gpt4 book ai didi

python - 将图例中的 Matplotlib 矩形更改为圆形

转载 作者:行者123 更新时间:2023-11-30 23:20:09 26 4
gpt4 key购买 nike

考虑以下绘图代码:

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 代码相当厌恶,尤其是代理艺术家的使用。有没有一种简单的方法可以做到这一点?

最佳答案

你们很接近。您只需要使用 Line2D 艺术家并像平常一样设置其属性:

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

关于python - 将图例中的 Matplotlib 矩形更改为圆形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25688859/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com