简体   繁体   中英

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.

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). Matplotlib plots a graph with one point, which does not show, because the default style does not highlights points, it only prints graphs.

You need to fix the code in addForce() to produce arrays for both variables.

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