I've written a simple plotting routine. The problem I'm having is that for each "dataset" I'm plotting, I'm getting two dots in the legend. See the figure with free-hand red arrows.
Here's the code:
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')
Any ideas how to get this down to a single dot per dataset?