Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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() 

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading