1
Hello community of Stackoverflow :)
I am developing a small code that will plot you from 2 filled lists from an equation while a while condition is not satisfied.
Once the lists are filled in, I use matplotlib to plot the two-dimensional graph with the extracted values, but it’s a lot of values and I’d like to know if you can only plot points at specific intervals, because if I plot them all, memory usage of my PC goes up to 100% and Python crashes and gives memory error. There would be a way to optimize this process?
For example, using the range of one in a nanometer (which is the case I’m trying to solve)
# Modelando a energia do fóton em uma equação
from matplotlib import pyplot as plt
h = 1.05457168 * 10**(-34) # J * s
c = 299792458.0 #m/s
i = 0.000004 #metros
energias =[]
wavelenghts=[]
while (i!=0.000007):
E = (h*c)/i
energias.append(E)
wavelenghts.append(i)
i=i+0.000001
print (energias)
print (wavelenghts)
plt.plot (energias, wavelenghts, color='blue', marker = 'o', linestyle = 'solid')
you can use a for to set an interval for the calculation
– Elton Nunes
How? : ( I thought q would fall into the same problem, due to the number of digits between the values.
– Kioolz
onosendai has already corrected your script with minimal effort
– Elton Nunes