传奇获得多个点

时间:2013-09-23 17:06:17

标签: python matplotlib

我写了一个简单的绘图程序。我遇到的问题是,对于我正在绘制的每个“数据集”,我在图例中得到两个点。用自由红色箭头看图。

enter image description here

以下是代码:

from collections import OrderedDict
from itertools import cycle

import matplotlib.backends.backend_agg
from matplotlib.figure import Figure


def simple_scatter(data, colors='rbgcmyk', no_legend=False):
  """Create a simple scatter plot."""
  data = OrderedDict(data)
  fig = Figure()
  matplotlib.backends.backend_agg.FigureCanvasAgg(fig)
  ax = fig.add_subplot(111)
  colors = cycle(colors)
  for label, points in data.iteritems():
    x, y = tuple(zip(*points))[:2]
    ax.plot(x, y, 'o', color=next(colors), label=label)

  if not no_legend:
    ax.legend(loc='best', shadow=True, fancybox=True)

  return fig


figure = simple_scatter([('Foo', ((1, 2), (3, 4))),
                         ('Bar', ((2, 3), (3, 5))),
                         ('Baz', ((2, 2.5), (3, 4.5)))])
figure.savefig('foo.png')

如何将每个数据集分成一个点?

1 个答案:

答案 0 :(得分:2)

ax.legend(loc='best', shadow=True, fancybox=True, numpoints=1)