简体   繁体   中英

Python, Pyplot: Change appearance of axis without changing axis itself

I have an array ( grmf ) of 2000 values, corresponding to a measurement scanning 7990 - 8010 MHz. The x values are stored from 0 to 1999.

import numpy as np
from matplotlib import pyplot as plt

xaxis = np.arange(2000)
grmf = 3 * xaxis    #let's just use this as dummy data
plt.plot(xaxis, grmf, label="measurement")
plt.show()

I want the x axis to simply display the values 7990 (corresponding to 0) and 8010 (corresponding to 1999) so that it's easier to identify where a peak is roughly located by first glance eg

Since there are other functions in the plot and xaxis is used in more ways than just this plot I can neither change the axis nor the array xaxis but just want to change the graphical appearance. From what I've found it seems like put.xticks seems to be the way to go, but it hasn't really worked out yet the way I want it.

Hmm, I'm not really sure why xticks isn't working for you. If I understand what you want to do, you just need one more line, so it would look like this:

import numpy as np
from matplotlib import pyplot as plt

xaxis = np.arange(2000)
grmf = 3 * xaxis    #let's just use this as dummy data
plt.plot(xaxis, grmf, label="measurement")
plt.xticks([0, 500, 1000, 1500, 1999], [7990, 7995, 8000, 8005, 8010])
plt.show()

I've added a few more values as it's quite simple to figure out which corresponds to which, but you can of course only keep 0 and 1990 if that's what you want. Hopefully this is what you were looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM