Editing bounds to get rid of white-space within a

2019-08-30 08:55发布

问题:

![Left: Data from 2000-2040, Right: Data from 2001-2039][2]

Is there a way I can manually edit the bounds of my plot? When my x axis data runs from 2000 to 2040 matplotlib rearranges the plot such that a lot of white-space is produced on both the left and right sides of the plot, as in the left picture. However when I change my x axis data from 2001 to 2039 there is no whitespace as in the right picture. I suspect this happens because of how matplotlib automatically arranges the ticks. The question is how can the x-ticks be manipulated manually to avoid unnecessary whitespace? Any ideas?

回答1:

You can use the various pyplot functions called xlim, ylim (to set the limits of the axes), xticks, yticks (to set the tick positions) etc. Read the documentation.