Scatter Plots looks linear when it should be no-linear

Howdy folks;

Can someone please explain why my plotly graphs look different than what Iโ€™m showing below:

image

These graphs were generated in google spreadsheets.

This is what the same graphs look like in ploty:

Here is the code that I used to generate the plots:

# Math library
import math

# Plotly graph object library
import plotly.graph_objects as go

# Library used to make subplots (side by side plots)
from plotly.subplots import make_subplots

# Library to handle array and array-like objects
import numpy as np

def createListOfHeights(height):
    ''' Function used to create a list of heights
        that will be used to perform other calculations
        and visualizations
    '''
    # Initialize a list
    heightList = []
    
    # Create a list of heights that we can use to analyze
    for height in range(x+1):
        heightList.append(height)
    
    return heightList

# height
x = 381

# Acceleration due to gravity
a = 9.8

# List to hold time values
time_list = []

# List to hold velocities
velocity_list = []

# Create a list of heights to calculate
# by calling a function
height_list = createListOfHeights(x)

for height in height_list:
    
    # Calculate the time
    time = math.sqrt((2 * height) / a)
    # Add it to the time list
    time_list.append(time)
    
    # Calculate the velocity
    velocity = a * time
    # Add the velocity to the velocity list
    velocity_list.append(velocity)

# Create a figure object that will 
# contain multiple plots
fig = make_subplots(rows = 1, 
                    cols = 2,
                    specs = [[{"type": "xy"}, {"type": "xy"}],
                            ],
                    subplot_titles = ("Height (m) vs Time (sec)", "Velocity (m/s) vs. Time (sec)")
                   )

# Generate a Height vs Time Graph
fig.add_trace(go.Scatter(x = height_list,
                         y = time_list,
                         mode = 'lines',
                         name = 'Height vs. Time',
                        ),      
                         row = 1, 
                         col = 1
             ); # The ; supresses output. Remove the ; to see what happens

fig.update_xaxes(#tickangle = 90,
                 title_text = "Height (m)",
                 #title_font = {"size": 20},
                 #title_standoff = 25,
                 row = 1,
                 col = 1,
                 );

fig.update_yaxes(#tickangle = 90,
                 title_text = "Time (sec)",
                 #title_font = {"size": 20},
                 #title_standoff = 25,
                 row = 1,
                 col = 1,
                 );

# Generate a Velocity vs. Time Graph
fig.add_trace(go.Scatter(x = velocity_list,
                         y = time_list,
                         mode = 'lines',
                         name = 'Velocity vs. Time'
                        ),
                         row = 1, 
                         col = 2
             ); # The ; supresses output. Remove the ; to see what happens

fig.update_xaxes(#tickangle = 90,
                 title_text = "Velocity (m/s)",
                 range = [0, 90],
                 #title_font = {"size": 20},
                 #title_standoff = 25,
                 row = 1,
                 col = 2,
                 );

fig.update_yaxes(#tickangle = 90,
                 title_text = "Time (sec)",
                 range = [0, 9],
                 #title_font = {"size": 20},
                 #title_standoff = 25,
                 row = 1,
                 col = 2,
                 );

fig.update_layout(showlegend = False, 
                  title_text = "Height and Velocity vs Time Analysis",
                  height = 500,
                  width = 700
                 );

# Generate graph
fig.show()

To generate the graph in the spreadsheet program,

a = 9.8
height = 381

I created 3 columns:

  • one for heights, starting from 0 to 381
  • one that calculated time using the following formula: time = sqrt((2 * height) / a)
  • one that calculated velocity using the following formula: velocity = a * time

Using those values I generated the graphs in the spreadsheet program.

Iโ€™d really appreciate it if someone could explain why Velocity vs Time looks linear, where in the spreadsheet program it looks non-linear.

Also, can someone please help me adjust the settings so the graph looks right?

Thanks everyone!

Maybe Iโ€™m misunderstanding something, but why do you expect something different than a linear curve for velocity vs time?

a is a constant

1 Like

Hi;

Iโ€™m just curious why the graphs are different between google sheets and plotly.

This isnโ€™t the first time Iโ€™ve encountered this circumstance, but itโ€™s the first time Iโ€™ve documented it so figured Iโ€™d ask a question.

Given that time is non-linear, I immediately assumed that the output of velocity would probably be non-linear as well, so assumed that Google was a more correct representation.

That said, Iโ€™m pretty dumb when it comes to math and physics though, so I could very well be ignorant about things in this circumstance.

Hope that makes sense.

HI @iacisme,

I assume the google chart to be erroneous because the velocity vs time should show a linear behavior as the acceleration is constant.

Are you sure the google graph is plotting the exact same values? (time_list & velocity_list)

A bit background of information (if interested)

2 Likes

Hey, thanks for that reference, it does clear it up.

Much appreciated.

P.S. The weird thing is that both the google spread sheets, and python, produce the exact same values for time and acceleration. I compared the spread sheet columns to the lists created in python, and theyโ€™re 1 to 1.

In any case, at least I have an understanding to not take graphs at face value.

Cheers!

1 Like

Hi @iacisme , it looks like the x-axis in the google chart is not linear, and so what is a linear relationship ends up looking different in the graph. You can verify this by looking at the difference between adjacent x values - the first two have a difference of about 8 seconds, whereas those on the right only have a difference of 2.5 seconds.