I am trying to plot a graph for a cylinder. Here are my functions for finding volume of the cylinder which is v(r,h)= pi*r^2*h
. I don't know how to plot since this is my first attempt with python but these are my codes so far.
def compute_cylinder_area(r,h):
h = float(h)
pi = 3.14159
surface_area = 2 * pi * r ** 2 + 2 * pi * r * h
return surface_area
h=4
r =array([1,2,3,4,5])
r_new = 3
r_new = float(r_new)
print(compute_cylinder_area(r_new,h))
print(compute_cylinder_area(r,h))
How can I create a plot of radius( x-axis
) versus cylinder volume ( y axis
) with the volume of cylinder with height 2,4
and 6
and the radius ranging from 0.0
to 10.0
. Also, how can I plot 3
volume curves as a function of radius on the figure?? I also need to label each curve and add axis label and a legend to the figure.
Once you have a list of x_values
and y_values
, use
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1)
ax.plot(x_values, y_values)
fig.show()
You can also do this an interactive fashion to plot on the "active" axes, but the object-oriented approach shown here will be more effective in teaching you programming skills. Read more about the plot function at http://matplotlib.org/ where you can enter plot
into the search box at the right and follow the link the method of an Axes: matplotlib.axes.Axes.plot
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.