繁体   English   中英

圆柱图

[英]Plot graph for a cylinder

我正在尝试绘制圆柱图。 这是我用于查找圆柱体积v(r,h)= pi*r^2*h 我不知道如何绘制,因为这是我第一次尝试使用python,但是到目前为止,这是我的代码。

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))

如何创建半径( x-axis )对圆柱体体积( y axis )的图,圆柱体的体积为2,46 ,半径范围为0.010.0 另外,如何在图中绘制3体积曲线作为半径的函数? 我还需要标记每条曲线,并在图中添加轴标签和图例。

一旦有了x_valuesy_values的列表,请使用

import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1)
ax.plot(x_values, y_values)
fig.show()

您也可以通过交互方式在“活动”轴上进行绘制,但是此处显示的面向对象方法将更有效地教您编程技能。 了解更多关于在绘图功能http://matplotlib.org/可以在其中输入plot成在右侧的搜索框,然后按照该链接的轴的方法: matplotlib.axes.Axes.plot

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM