简体   繁体   中英

How to plot a cyclical graph on x-y plot

Not sure how to word this correctly. I have longitude data, which sometimes goes from -150 to 150 in consecutive data points, for example. I would like to express the minimum difference graphically. So for points x1 = -150 and x2 = 150, the minimum difference is really only 60, since after reaching -180, it flips sign and counts down to 150 (as opposed to going the other way, from -150 to 0, then from 0 to 150, which would be a difference of 300). Considering the min and max of the data (-140 and 160, for example), I'd like to create a graph where y-axis would go like (from top to bottom):

[160, 170, +-180, -170, -160, -150, -140]

so here's the graph i have: 在此处输入图片说明

here's how i converted all the big jumps into small jumps: 在此处输入图片说明

However, I would like the y-axis not to have values less than -180. Instead, I'd like it to flip back to positive numbers, so it's more accurate (so below -180, it would go to 179, 178, etc).

You can use numpy's built-in unwrap method after converting your angle data to radians. It will automatically add 2*pi each time your data crosses from -180 to 180.

    def normalize(l):
        l2 = [l[0]]
        for i in range(1, len(l)):
            diff = (l[i] - l2[i-1])%360
            if diff != 0:
                diff2 = diff - (diff/abs(diff))*360
            if abs(diff2) < abs(diff):
                diff = diff2
            l2.append(l2[i-1] + diff)
        return l2

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