12

In Matplotlib I need to draw a graph with points on the x-axis on each integer between 1 and 5000 and on the y-axis only in a very limited range.

Matplotlib automatically compacts everything to let all the data fit on a (landscape) page. In my case I would like the x-axis to be as large as possible so that all points are clearly visible. Right now there's just a thick coloured line as opposed to scattered points.

How can I do this?

(I'm saving to pdf, if that helps)

Ricky Robinson
  • 19,969
  • 40
  • 122
  • 177

1 Answers1

17

You can always try to specify the dimensions (in inches) of the figure you are creating. Something along the following line might help:

fig = plt.figure(figsize=(20, 2))
ax = fig.add_subplot(111)
ax.plot(x, y)

The figsize takes a tuple of width, height in inches.

Loïc Séguin-C.
  • 1,636
  • 1
  • 12
  • 14
  • 7
    if you add then `plt.tight_layout()` the subplot will get stretched to occupy as much of the figure canvas as possible, accounting for axis and ticks labels – Francesco Montesano Feb 01 '13 at 09:56