-1

I am trying to modify the graph graph specifically I do not like seeing the spaces to the left and to the right on the x axis and would like it to squeeze to fit.

the values of the x axis are datetime objects.

xmin,xmax = plt.xlim()
print(xmax)
print(xmin)

returns

17707.15
16757.85

What is the proper way to modify these limits? Should I convert the correct datetime object to an int and set xlim using that. Or is there a function within matplotlib that will remove these gaps (only on the x axis) for me.

Kevin Riordan
  • 149
  • 1
  • 8
  • Possible duplicate of [How can I change the x axis in matplotlib so there is no white space?](https://stackoverflow.com/questions/42045767/how-can-i-change-the-x-axis-in-matplotlib-so-there-is-no-white-space) – user3483203 May 14 '18 at 19:11
  • It is the same problem with a different solution. Also the question is worded differently. and identifies a specific conceptual issue regarding xlim()'s interpretation of datetime – Kevin Riordan May 14 '18 at 19:27

1 Answers1

1
ax.autoscale(enable=True, axis='x', tight=True)

produced

enter image description here Sourced from https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.autoscale.html

Kevin Riordan
  • 149
  • 1
  • 8