Home > front end >  ('float' object cannot be interpreted as an integer) problem is there another built-in fun
('float' object cannot be interpreted as an integer) problem is there another built-in fun

Time:05-25

This is my code:

import numpy as np
import matplotlib.pyplot as plt

The problem lies here as i would like to plot the points from -0.4 to 0.8 in increments of 0.01 as there is an important part of the graph that im missing which happens after x = 0.6

x = np.linspace(-0.4,1,0.01)
y = np.sqrt(((47.9-72*x)/5))

plt.figure(figsize = (10,10))
plt.plot(x,y,label = "k", linestyle = "-", color = 'Blue')

plt.xlabel("delta ($\Delta$) [m]")
plt.ylabel("Vc [m/s] ") #Velocity after it passes point C 
plt.title("TITLE")
plt.xlim([-0.4, 1])
plt.ylim([0,4.0])
plt.legend()
plt.grid()
plt.show()

CodePudding user response:

You can just use range: range(-.4,.8,.01). Note that this omits the upper limit, so if you want to include .8, you should use range(-.4,.81,.01)

CodePudding user response:

As @BigBen stated, np.linspace(...) does not take float values, it takes an integer to represent the number of points between start and stop. You can not have half of a slice, so non-integers will throw an error, see more in the Your plot

  • Related