用Matplotlib绘制Python图形

2024-04-29 19:39:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我不熟悉Python和matplotlib。我试着用Python绘制方程图,但做不到。你能帮我找出哪里做错了吗?在

我的代码在这里:

import matplotlib.pyplot as plt

def plotgraph ():
    T = -14
    index = 0
    ro = []
    while(T<=14):
        ro.append( 1000 - ((T-4)*(T-4)) / 180)
        T = T + 0.001
        plt.plot(ro[index],T)
        index = index +1
    return

plotgraph()
plt.show()

Tags: 代码importindexroplotmatplotlibdefas
1条回答
网友
1楼 · 发布于 2024-04-29 19:39:45

下面是如何使用matplotlib绘制直线图:

import matplotlib.pyplot as plt
import numpy as np

T = np.linspace(-14,14, num=201)
ro = 1000 - ((T-4)*(T-4)) / 180

plt.plot(T, ro)

plt.show()

enter image description here

相关问题 更多 >