Matplotlibと「同様の」問題が発生しています。これは、1つのラベルを持つ複数の異なるマーカーを持つ凡例です。この質問のおかげで、次のことを達成できました。凡例の2つのPyplotパッチを組み合わせます。
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()
しかし、私の2つの(金星と火星)マーカーは凡例で重なっています。ハンドルの長さで遊んでみましたが、うまくいかないようです。どんな提案やコメントも役に立ちます。
これが私の回避策MWEです。私は実際に2つの追加の「プロット」をプロットしpoint_g
、point_r
それらには使用する凡例ハンドルがあります。次に、白い正方形のマーカーを使用してそれらを覆います。必要に応じて残りのプロットをプロットします。
import matplotlib.pyplot as plt
plt.rc('text', usetex=True)
plt.rc('text', **{'latex.preamble': '\\usepackage{wasysym}'})
plt.rc('lines', **{'markersize':20})
fig = plt.figure()
point_g, = plt.plot((0,), (0,), ls='none', marker='$\\male\\female$', mec='g')
point_r, = plt.plot((0,), (0,), ls='none', marker='$\\male\\female$', mec='r')
plt.plot((0,), (0,), marker='s', mec='w', mfc='w')
plt.plot(range(3), range(1,4), ls='none', marker='$\\male$', mec='g')
plt.plot(range(3), range(2,5), ls='none', marker='$\\male$', mec='r')
plt.plot(range(1,4), range(3), ls='none', marker='$\\female$', mec='g')
plt.plot(range(2,5), range(3), ls='none', marker='$\\female$', mec='r')
plt.axis([-0.1, 4.1, -0.1, 4.1])
plt.legend((point_g, point_r), ('Green', 'Red'), markerscale=1.6, numpoints=1,
borderpad=0.8, handlelength=3, labelspacing=1)
plt.show()
注:Unicodeシンボルを使用する場合は、LaTeXプリアンブルは必要ありません。私のシステム(Linux)でそれらを動作させることができなかったので、LaTeXシンボルを使用しました。この方法は、単に削除し、すべてのシンボルで動作するplt.rc
コマンドや変更を\\male
して\\female
、あなたのUnicode文字に。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加