0% found this document useful (0 votes)
43 views3 pages

Michael Jonathan Dr. Hugh Williams PHYS 414-401 23 January 2019 Basic Function Plot

The document contains code to generate two plots using the matplotlib library in Python. The first plot generates 100 x-values from 0 to pi and calculates the sine of each value to plot a basic sine wave. The second plot calculates the relativistic mass of an electron based on its velocity as a fraction of the speed of light from 0 to 0.99 and plots the relationship. Both plots are saved as image files and displayed.

Uploaded by

MikeJonathan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views3 pages

Michael Jonathan Dr. Hugh Williams PHYS 414-401 23 January 2019 Basic Function Plot

The document contains code to generate two plots using the matplotlib library in Python. The first plot generates 100 x-values from 0 to pi and calculates the sine of each value to plot a basic sine wave. The second plot calculates the relativistic mass of an electron based on its velocity as a fraction of the speed of light from 0 to 0.99 and plots the relationship. Both plots are saved as image files and displayed.

Uploaded by

MikeJonathan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Michael Jonathan

Dr. Hugh Williams


PHYS 414-401
23 January 2019
Basic Function Plot
Plot 1
# Load the numpy library
import numpy as np

#Load the math library


import math

# Load the the pyplot library giving it the nickname "plt" for short
import matplotlib.pyplot as plt

# Create an array of 100 linearly-spaced points from 0 to 9


x = np.linspace(0,math.pi,100)
print ("x=",x)

# Calculation the sin of the numbers in the array


y = np.sin(x)
print ("y=",y)

# Create the "plot" in memory (doesn't draw it yet)


plt.plot(x,y)

# Adding Labels
plt.title('Michael Jonathan')
plt.xlabel('Angle [radians]')
plt.ylabel('Magnitude of Displacement [mm]')

# Save the plot in a file


# I have no idea why, but this needs to be before the "show" command?!
plt.savefig('basicfunctionplot.png')

# Draw the plot to the screen


plt.show()
Plot 2
# Load the numpy library
import numpy as np

# Load the the pyplot library giving it the nickname "plt" for short
import matplotlib.pyplot as plt

# Create an array of 100 linearly-spaced points from 0 to 9


x = np.linspace(0,0.99,100)
print ("x=",x)

# Calculation the sin of the numbers in the array


y = 9.10938356*(10**(-31))*((1-(x**2))**(-0.5))
print ("y=",y)

# Create the "plot" in memory (doesn't draw it yet)


plt.plot(x,y)

# Adding Labels
plt.title('Velocity Dependence of the Electron Mass')
plt.xlabel('Velocity as a Fraction of the Speed of Light')
plt.ylabel('Relativistic Electron Mass [kg]')

# Save the plot in a file


# I have no idea why, but this needs to be before the "show" command?!
plt.savefig('velocity_dependence_electron_mass.png')

# Draw the plot to the screen


plt.show()

You might also like