I am doing a course in edx. While plotting in python, there is always a blank space before the beginning of the plot. In StackExchange, I have found a solution, which is mentioning the axis limit. However, in maximum cases, the starting points of the plot is unknown. So, Is there any solution to this without manipulating the axis limits manually? A graph is attached herewith for making things more clear.

enter image description here


1 Answer 1


This stackoverflow answer should solve your issue. You can use either plt.margins(x=0) or ax.margins(x=0) to remove all margins on the x-axis.

  • $\begingroup$ But this makes the plot congested on the right side, which doesn't look good. Can I do something to only adjusting the left side of the plot? $\endgroup$
    – Faisal
    Commented Mar 7, 2021 at 16:35
  • $\begingroup$ Try removing the top and right axis limits to remove clutter margins(x=0,y=0); gca().spines[['right', 'top']].set_visible(False) $\endgroup$
    – MRule
    Commented Jun 7, 2023 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.