-1

It seems pyplot.plot does not align the x and y axes to their respective data endpoints. There are always padded gaps between the plot axes and boundaries and the actual data plot. How can you force a tighter layout for plots such that the plot axes begin and end at their respective terminal data values?

Here's an example of what I mean, with a simple plot:

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0,101)
plt.plot(x)

example plot

As you can see, the plot origin (0,0) and the figure axes origin or intersection (bottom left corner of figure box) are not the same. I want to know how to remove the padding so that the line starting fromx[0] begins from the bottom left corner of the figure.

Alnitak
  • 2,068
  • 2
  • 12
  • 24

1 Answers1

1
import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0,101)
y = np.arange(len(x))
plt.plot(x)
plt.xlim([x.min(), x.max()])
plt.ylim([y.min(), y.max()])
plt.show()
Melvin
  • 1,530
  • 11
  • 18