0

I am using phyton 3.6 and want to limit the number of ticks to 5 in my plot. However, when using this code example the y-axis doesn't appear in ascending order. The x-axis, on the other hand, works fine. What am I doing wrong? An example plot is given here.

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, MaxNLocator,FuncFormatter, ScalarFormatter

plt.figure()
ax = plt.axes()
ax.plot(date, frequency,color='gray') 
ax.xaxis.set_major_locator(MaxNLocator(5))
ax.yaxis.set_major_locator(MaxNLocator(5))
plt.xlabel('Timestamp')
plt.ylabel('Frequency (GHz)')
plt.show()
  • Welcome to Stack Overflow! Please take a moment to read [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask). You need to provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) that includes a toy dataset (refer to [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples)) – Diziet Asahi Apr 24 '20 at 12:01
  • Possibly the frequency array contains strings, or the imported `FuncFormatter` is used in a strange way. Note that a locator doesn't change the order of the ticks, so you should first test without setting `MaxNLocator` and once that goes well, incorporate the locator. – JohanC Apr 24 '20 at 14:56
  • Yes, apparently there was a string in my array. Thanks! – doncarlos31415 Apr 25 '20 at 04:07

0 Answers0