pythonmatplotlib

How to limit the x axis in matplotlib that labeled with date?


I have a chart of programming languages popularity which each element of x axis are labled with date object, I want to limit the max date to 2012 while mean is auto (untouched).

How can I do it?

I tried using plt.xlim(None, 2012) and it took me to 1975.

Edit: I tried passing touple and list also, but no luck.


Solution

  • As explained here, you can set just the max xlim using the right kwarg:

    plt.xlim(right=2012)
    

    Of course, the value passed to the right kwarg may need to be a datetime object, rather than just an int equal to the year in question.