Python matplotlib x-axis labels displayed but 1

I have two lists, I am making a basic line diagram with an entry in ipython. It should be basic, but I keep getting a screwed x axis like this ... it should start on Saturday.

enter image description here

What is wrong with my code that makes my hash axis all spoiled? It should start on Saturday, the first value on my date list. (ignore the y axis values ​​here, I just made count_list values ​​for this example.)

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

count_list = [5,7,2,3,1,7,3]
date_list = ['Saturday', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']

fig=plt.figure(figsize=(12,3.5))
ax=fig.add_subplot(111)
ticknumbs = np.arange(7)
ax.plot(ticknumbs, count_list, color='r', linewidth=1.0)
ax.set_xticklabels(date_list, rotation = 45) #WHHHHY ARENT U WORKING
ax.margins(x=0.05, y=0.05)
+4
source share
1 answer

Take out the line ax_margins(). You crop your first data point immediately.

enter image description here

+3
source

All Articles