简体   繁体   中英

How can I make parabolic curves in matplotlib?

How can I make a graph like this with matplotlib ?

At first, I thought it would just need to graph X and Y like

X = [1,2,3,4,5,6,7,8,9,10]
Y = [10,9,8,7,6,5,4,3,2,1]

Then throw it up with plt.plot(X, Y) but clearly X and Y are relative(?) so it doesn't.

I don't particularly care about having colours, like the colouring in the image.

Given your X and Y lists, you can turn them into the 'curve' figure like this:

import matplotlib.pyplot as plt

X = [1,2,3,4,5,6,7,8,9,10]
Y = [10,9,8,7,6,5,4,3,2,1]

for x,y in zip(X, Y):
    x1 = [0, x]
    y1 = [y, 0]
    plt.plot(x1, y1)
plt.show()

(and I think the result is a hyperbola. To get a parabola, the axes would need to be at a different angle)

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