简体   繁体   English

如何将我的 python 代码修复为 plot 一个数字?

[英]how to fix my python code to plot a figure?

My code is exiting with code 0 so there is no mistakes in my code, but it is still running without plotting the flow over the cylinder I wanted to have, can someone help me fix this problem?我的代码以代码 0 退出,因此我的代码中没有错误,但它仍在运行而没有绘制我想要的圆柱体上的流,有人可以帮我解决这个问题吗?

    import sympy as s
    import matplotlib.pyplot as plt
    import numpy as np

    from sympy.abc import x,y


    def cylinder_stream_fct(U=1,R=1):
        r=s.sqrt(x**2+y**2)
        theta=s.atan2(y,x)
        return U*(r-R**2/r)*s.sin(theta)
    def velocity_field(psi):
        u=s.lambdify((x,y), psi.diff(y), 'numpy')
        v=s.lambdify((x,y), -psi.diff(x), 'numpy')
        return u,v
    def plot_streamlines(ax, u, v,xlim=(-1,1), ylim=(-1,1)):
        x0, x1=xlim
        y0, y1=ylim
        Y,X= np.ogrid[y0:y1:100j,x0:x1:100j]
        ax.streamplot(X,Y,u(X,Y),v(X,Y),color='red')
    def format_axes(ax):
        ax.set_aspect('equal')
        ax.figure.subplots_adjust(bottom=0, top=1, left=0, right=1)
        ax.xaxis.set_ticks([])
        ax.yaxis.set_ticks([])
        for spine in ax.spines.values():
            spine.set_visible(False)
    psi=cylinder_stream_fct()
    u,v=velocity_field(psi)
    xlim=ylim=(-3,3)
    fig, ax=plt.subplots(figsize=(4, 4))
    plot_streamlines(ax, u, v, xlim, ylim)
    c=plt.Circle((0,0), radius=1,facecolor='none')
    ax.add_patch(c)

    format_axes(ax)

You don't have你没有

plt.show()

Which renders and blocks the program from exiting.它呈现并阻止程序退出。

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

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