图例上的多个标记
Multiple marks on a legend
我为卫星数据图像中绘制的一些标记创建了图例。我不知道如何为我正在绘制的不同位置设置多个标记。
import matplotlib.patches as mpatches
colors = ["g", "w", "y", "b", "w", "g"]
texts = ["San Luis","Tupungato", "Tierra Alta", "Tokio", "Cordoba","Sierras de Cordoba"]
patches = [plt.plot([],[], marker="o", ms=10, ls="", mec=None, color=colors[i],
label="{:s}".format(texts[i]) )[0] for i in range(len(texts)) ]
plt.legend(handles=patches, bbox_to_anchor=(0.5, 0.5),
loc='center right', ncol=2, facecolor="plum", numpoints=1 )
我希望每个元素都有不同的标记,而不是用圆圈显示所有元素。
您需要为每个 plot()
指定不同的 marker
选项。这是更新后的代码和示例输出图。
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
colors = ["g", "w", "y", "b", "w", "g"]
texts = ["San Luis","Tupungato", "Tierra Alta", "Tokio", "Cordoba","Sierras de Cordoba"]
# a list of marker shapes
markers = ["o", "^", "v", "<", ">", "s"]
patches = [plt.plot([],[], marker=markers[i], ms=10, ls="", mec=None, color=colors[i],
label="{:s}".format(texts[i]) )[0] for i in range(len(texts)) ]
plt.legend(handles=patches, bbox_to_anchor=(1, 1),
loc='upper right', ncol=2, facecolor="plum", numpoints=1 )
我为卫星数据图像中绘制的一些标记创建了图例。我不知道如何为我正在绘制的不同位置设置多个标记。
import matplotlib.patches as mpatches
colors = ["g", "w", "y", "b", "w", "g"]
texts = ["San Luis","Tupungato", "Tierra Alta", "Tokio", "Cordoba","Sierras de Cordoba"]
patches = [plt.plot([],[], marker="o", ms=10, ls="", mec=None, color=colors[i],
label="{:s}".format(texts[i]) )[0] for i in range(len(texts)) ]
plt.legend(handles=patches, bbox_to_anchor=(0.5, 0.5),
loc='center right', ncol=2, facecolor="plum", numpoints=1 )
我希望每个元素都有不同的标记,而不是用圆圈显示所有元素。
您需要为每个 plot()
指定不同的 marker
选项。这是更新后的代码和示例输出图。
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
colors = ["g", "w", "y", "b", "w", "g"]
texts = ["San Luis","Tupungato", "Tierra Alta", "Tokio", "Cordoba","Sierras de Cordoba"]
# a list of marker shapes
markers = ["o", "^", "v", "<", ">", "s"]
patches = [plt.plot([],[], marker=markers[i], ms=10, ls="", mec=None, color=colors[i],
label="{:s}".format(texts[i]) )[0] for i in range(len(texts)) ]
plt.legend(handles=patches, bbox_to_anchor=(1, 1),
loc='upper right', ncol=2, facecolor="plum", numpoints=1 )