gpt4 book ai didi

python matplotlib 绘制许多具有相同参数的子图

转载 作者:行者123 更新时间:2023-11-28 22:34:47 24 4
gpt4 key购买 nike

我的剧情是这样的

fig = plt.figure(figsize=(7,3))                                               
ax1 = fig.add_subplot(1,3,1)
ax2 = fig.add_subplot(1,3,2)
ax3 = fig.add_subplot(1,3,3)
ax1.scatter(x11, y11, s=50, alpha=0.5, c='orange', marker='o')
ax1.scatter(x12, y12, s=50, alpha=0.5, c='blue', marker='s')
ax2.scatter(x21, y21, s=50, alpha=0.5, c='orange', marker='o')
ax2.scatter(x22, y22, s=50, alpha=0.5, c='blue', marker='s')
ax3.scatter(x31, y31, s=50, alpha=0.5, c='orange', marker='o')
ax3.scatter(x32, y32, s=50, alpha=0.5, c='blue', marker='s')

一遍又一遍地设置 s=50, alpha=0.5 似乎有点多余。有没有办法一劳永逸地设置它们?还有颜色和标记,有没有办法把它们写在一个地方,这样更容易修改?

最佳答案

你可以这样做:

fig = plt.figure(figsize=(7,3))                                               
ax1 = fig.add_subplot(1,3,1)
ax2 = fig.add_subplot(1,3,2)
ax3 = fig.add_subplot(1,3,3)

xs = [x11, x12, x21, x22, x31, x32]
ys = [y11, y12, y21, y22, y31, y32]
cs = ['orange', 'blue']
ms = 'os'

for j in xrange(len(xs)):
ax1.scatter(xs[j], ys[j], s=50, alpha=0.5, c=cs[j % 2], marker=ms[j % 2])

关于python matplotlib 绘制许多具有相同参数的子图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38753766/

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