gpt4 book ai didi

matplotlib - 具有相同标签的不同散点图标记

转载 作者:行者123 更新时间:2023-12-01 11:33:19 25 4
gpt4 key购买 nike

我遇到了与 Matplotlib, legend with multiple different markers with one label 类似的问题.由于这个问题Combine two Pyplot patches for legend,我能够实现以下目标.

fig = pylab.figure()
figlegend = pylab.figure(figsize=(3,2))
ax = fig.add_subplot(111)
point1 = ax.scatter(range(3), range(1,4), 250, marker=ur'$\u2640$', label = 'S', edgecolor = 'green')
point2 = ax.scatter(range(3), range(2,5), 250, marker=ur'$\u2640$', label = 'I', edgecolor = 'red')
point3 = ax.scatter(range(1,4), range(3), 250, marker=ur'$\u2642$', label = 'S', edgecolor = 'green')
point4 = ax.scatter(range(2,5), range(3), 250, marker=ur'$\u2642$', label = 'I', edgecolor = 'red')
figlegend.legend(((point1, point3), (point2, point4)), ('S','I'), 'center', scatterpoints = 1, handlelength = 1)
figlegend.show()
pylab.show()

但是,我的两个(金星和火星)标记在图例中重叠。我尝试使用句柄长度,但这似乎没有帮助。任何建议或意见都会有所帮助。

最佳答案

一种可能的解决方法是在第一列中创建一个带有空白标签的两列图例:

figlegend.legend((point1, point2, point3, point4), (' ', ' ', 'S', 'I'), 
'center', scatterpoints = 1, ncol = 2)

legend with two columns

关于matplotlib - 具有相同标签的不同散点图标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30160683/

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