# Working of np.arrage() function i n a code

I have looked into the numpy.arrange() documentation, but couldn’t understand how the following command is working:
plt.xticks(numpy.arange(130000)[::20000][2:],[‘11AM day 1’,‘5:30PM day 1’,‘10PM day 1’, ‘3:30AM day 2’, ‘9AM day 2’],rotation=90)

Just for reference, it is part of the following snippet I am working on:
if plot==True:
fig,ax = plt.subplots(figsize=(6,5))
ax.plot(tt, yy, “-k”, linewidth=1, alpha=0.3)
ax.plot(tt, fitfunc(tt), “r-”, label=“Circadian Rhythm”, linewidth=2)
plt.xticks(numpy.arange(130000)[::20000][2:],[‘11AM day 1’,‘5:30PM day 1’,‘10PM day 1’, ‘3:30AM day 2’, ‘9AM day 2’],rotation=90)
plt.legend()
fig.tight_layout()
plt.show()

Hi Afaq,

You asked about the use of numpy.arange in this line of code:

``````plt.xticks(numpy.arange(130000)[::20000][2:],['11AM day 1','5:30PM day 1','10PM day 1', '3:30AM day 2', '9AM day 2'],rotation=90)
``````

Does this help?

``````>>> import numpy
>>> numpy.arange(130000)[::20000][2:]
array([ 40000,  60000,  80000, 100000, 120000])
``````

Quite frankly, I think that’s a silly use of numpy. Given that the axis
labels are hard-coded, there’s no harm in hard-coding the values as
well:

``````[40000,  60000,  80000, 100000, 120000]
``````

Or we could do this:

``````>>> numpy.arange(40000, 130000, 20000)
array([ 40000,  60000,  80000, 100000, 120000])
``````

or even just use this:

``````range(40000, 130000, 20000)
``````

Anything else is just obfuscating the meaning of the code, as you have
learned. Let’s dissect the code:

``````numpy.arange(130000)
# returns an array from 0 (included) to 130000 (excluded)

numpy.arange(130000)[::20000]
# makes a copy of the array with only every 20-thousandth element
# giving 0, 20000, 40000 etc

numpy.arange(130000)[::20000][2:]
# makes another copy this time skipping the first two elements
# giving 40000, 60000 etc.
``````

Being numpy, it is possibly that the last two steps might not make an
actual copy, it might be what numpy calls a “view”, but don’t worry