简体   繁体   English

为什么我的图表中的线没有出现?

[英]Why isn't the line in my graph showing up?

I want a graph that shows how much the objects acceleration is going up from the force.我想要一个图表来显示物体加速度从力上升了多少。 The line plot at the end is not showing anything but labels.最后的 plot 行只显示标签。

import numpy as np;
import matplotlib.pyplot as plt
import time as tme;

Acceleration, MASS = (float(0), float(2.5))
Force = 0


isMotion = False

def addForce(newtons):
  global Acceleration
  global MASS

  accelAmount = []

  repAmount = 0
  while repAmount < newtons:
    repAmount += 1

    accelAmount.append(repAmount)
    print(accelAmount)
    tme.sleep(.2)
  
  for i in accelAmount:
    Acceleration += float(1.5)
    ma = MASS * Acceleration
    global Force
    Force = ma
    print(f'Force = {round(Force)} Newtons | ({i})')
    global A
    A = Acceleration
    global F
    F = Force

addForce(10)
plt.plot(F, A)
plt.title('Force & Acceleration')
plt.xlabel('Force')
plt.ylabel('Acceleration')
plt.grid(True)
plt.show() 

That is because F and A are floats, not iterables (lists or arrays).那是因为FA是浮点数,而不是可迭代对象(列表或数组)。 Matplotlib plots a graph with one point, which does not show, because the default style does not highlights points, it only prints graphs. Matplotlib 绘制一个带有一个点的图形,它不显示,因为默认样式不突出显示点,它只打印图形。

You need to fix the code in addForce() to produce arrays for both variables.您需要修复addForce()中的代码,以便为这两个变量生成 arrays。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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