0

what I am trying to do is this :

Plot with legend inside

How do I extend my plot so that the legend is above my data points, but inside the plot?

oz123
  • 27,559
  • 27
  • 125
  • 187
tarrasch
  • 2,630
  • 8
  • 37
  • 61
  • 1
    see [this answer](http://stackoverflow.com/a/4701285/1301710) for placing legends – bmu May 30 '12 at 13:51

2 Answers2

1

Use the command xlim(0, 100) to set x-limits (or ax.set_xlim(0, 100) if you are using the object-oriented style of programming matplotlib)

SethMMorton
  • 45,752
  • 12
  • 65
  • 86
1

A better way would be to specify the size of your canvas by inches. So the fonts (default is 10 points, look smaller and so do the data points). You can choose any size you want,

# in this case 3 inches times 3 inches
fig = pyplot.figure(figsize=(3,3))
ax  = fig.add_subplot(111)

but be warned, you should then save your images to files instead trying to view them with show().

fig.savefig('mycoolgraph.png') # you could also you vector formats like PDF or SVG...

See also this question about saving the legend outside the figure.

Community
  • 1
  • 1
oz123
  • 27,559
  • 27
  • 125
  • 187