0

I am trying to create a simple bar chart with ticks on the x-axis represented by strings in the format YYYY-WW i.e. Year and Week of the Year.

My x labels are too dense as shown below.

enter image description here

In trying to alternate every other tick I came across this post - X-axis tick labels are too dense when drawing plots with matplotlib. This user had the same exact issue as myself and was also using the same format.

The suggestions described that the best way about this is to make the strings datetime objects, as matplotlib will automatically take care of the spacing in that case.

However I have not found any help suggesting how to convert this custom format into a datetime object.

  • In what format is your data/input? (pd.df etc.) In general, you'll have to [strptime](https://docs.python.org/3/library/datetime.html#datetime.datetime.strptime); formats see https://strftime.org/. Here, something like `%Y-%W` could work. – FObersteiner Oct 22 '20 at 14:28
  • My data is in a csv file. I then aggregate to get SUM of certain values over the week period. I have tried working with strftime however it converts my date into a string and that brings me back to square one – Rebecca Vella Oct 22 '20 at 14:33
  • 1
    `strftime` is to **f**ormat to string, `strptime` to **p**arse to `datetime`. the latter is what you want. – FObersteiner Oct 22 '20 at 14:35

0 Answers0