0

I am using the following code to make a graph and I end up with a black line of x ticks because there are way too many. I tried to specify only 10 with plt.locator but it didn't work. How can I reduce the number of xticks?Graph with too many xticks

fig=plt.figure()
sim_bore = sim_smp.loc[sim_smp['Group'] == group]
mes_bore = mes_smp.loc[mes_smp['Group'] == group]
plt.plot(sim_bore['Date'], sim_bore['Water_Level'] ,label='Simulated',ls ='-', 
markersize=2)    
plt.plot_date(mes_bore['Date'], mes_bore['Water_Level'], label='Measured',ls ='-')    
title = 'Drawdown at %s' %(group)
plt.title(title,fontsize=20)
plt.yticks(fontsize=16)
plt.xticks(fontsize=16)
plt.locator_params(axis='x', nbins=10)
plt.ylabel('Water Level (masl)', fontsize=18)
plt.xlabel('Time', fontsize=18)
ax1.legend(fontsize=20)  
emma_kth
  • 25
  • 2
  • Did you search with the title of your question? – wwii Jul 20 '22 at 03:14
  • Yes, but pyplot.locator_params(nbins=4) and the other answer did not work – emma_kth Jul 20 '22 at 03:20
  • [plt.locator_params not working as expected](https://stackoverflow.com/questions/52807374/plt-locator-params-not-working-as-expected),, – wwii Jul 20 '22 at 03:27
  • Are the xaxis values strings? - `mes_bore['Date'].dtype` `sim_bore['Date'].dtype`?? – wwii Jul 20 '22 at 03:29
  • Yes, they were strings, thanks so much. I changed them to datetime and then the plt.locator worked. – emma_kth Jul 20 '22 at 03:35
  • This is probably a duplicate question, but I haven't found a good fit yet. [You can answer your own question](https://stackoverflow.com/help/self-answer) if you like. Explain what was wrong and the code used to fix it. – wwii Jul 20 '22 at 03:42

0 Answers0