Howdy folks;
Can someone please explain why my plotly graphs look different than what Iโm showing below:
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!