Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matplotlib等高线_Matplotlib_Contourf - Fatal编程技术网

Matplotlib等高线

Matplotlib等高线,matplotlib,contourf,Matplotlib,Contourf,我对matplotlib中的等高线图有一些问题。我把我的地块划分为4个区域 a1=zeros((100,100)) a2=zeros((100,100)) a3=zeros((100,100)) a4=zeros((100,100)) x=np.linspace(x1,x2,100) #x1,x2,y1,y2 and so on are boundaries I didnt include here y=np.linspace(y1,y2,100) xneu=np.linspace(x2,

我对matplotlib中的等高线图有一些问题。我把我的地块划分为4个区域

a1=zeros((100,100))
a2=zeros((100,100))
a3=zeros((100,100))
a4=zeros((100,100))


x=np.linspace(x1,x2,100) #x1,x2,y1,y2 and so on are boundaries I didnt include here
y=np.linspace(y1,y2,100)

xneu=np.linspace(x2,x3,100)
yneu=np.linspace(y1,y2,100)

yo=np.linspace(y1,y3,100)

#Four areas X,Y X1,Y1 X2,Y2 X3,Y3

X, Y=np.meshgrid(x, y)
X1, Y1=np.meshgrid(xneu, y)

X2,Y2=np.meshgrid(x,yo)
X3,Y3=np.meshgrid(xneu,yo)

#filling my arrays with wanted values , f's are functions I haven't included here
for i in arange(0,len(y)):
    werte[i]=f(y[i])

for j in arange(0, len(xneu)):
    for i in arange(0, len(yneu)):
        werte2[i][j]=f1(xneu[i],yneu[j]) + f3(xneu[i],yneu[j]) + f5(xneu[i],yneu[j]) + f7(xneu[i],yneu[j]) + f9(xneu[i],yneu[j]) 

for i in arange(0,len(yo)):
    werte3[i]=f(y[i])

for j in arange(0, len(xneu)):
    for i in arange(0, len(yo)):
        werte4[i][j]=f1(xneu[i],yo[j]) + f3(xneu[i],yo[j]) + f5(xneu[i],yo[j]) + f7(xneu[i],yo[j]) + f9(xneu[i],yo[j])     

cs = plt.contourf(X, Y, werte, 10)    
ds = plt.contourf(X1, Y1, werte2, 10)
es = plt.contourf(X2, Y2, werte3, 10)    
fs = plt.contourf(X3, Y3, werte4, 10)
这就是我得到的情节:

问题是,这些比例不一样。通常,它应该“相互流动”。我并不是说绘图不平滑,我知道我可以通过增加plt.contourf函数中的10来改变这一点


出现此问题是因为我将绘图“划分”为四个区域吗?

因此我解决了此问题。我要谈谈contourf的本质。如果您有一个3x2网格的绘图,那么在第一行中您有您的

y1->x1、x2、x3

第二排是

y2->x1、x2、x3

第三排呢

y3->x1、x2、x3

这意味着,具有值的矩阵必须具有此结构

我不知道这一点,因为我必须处理4倍于100x100的网格区域,所以矩阵没有问题(但数值)。在我改变了矩阵的形状之后,我可以找出问题所在。 该条例及守则:

from numpy import pi,arange,cos,sinh, zeros
import numpy as np
import matplotlib.pyplot as plt


w=100
b=40
V0=10.0
a=200.0

x1=0
x2=w/2.0
x3=a/2

y1=0
y2=-b/2.0

y3=b/2.0


A1=(8*V0)/((1**2)*(pi**2)*sinh(((1*pi)/(2*b))*(a-w)))
A2=(8*V0)/((3**2)*(pi**2)*sinh(((3*pi)/(2*b))*(a-w)))
A3=(8*V0)/((5**2)*(pi**2)*sinh(((5*pi)/(2*b))*(a-w)))
A4=(8*V0)/((7**2)*(pi**2)*sinh(((7*pi)/(2*b))*(a-w)))
A5=(8*V0)/((9**2)*(pi**2)*sinh(((9*pi)/(2*b))*(a-w)))


werte=zeros((20, 50))
werte2=zeros((20, 50))
werte3=zeros((20, 50))
werte4=zeros((20, 50))

def f(y):
    global V0, b
    return (2*V0/b)*y + V0


def f1(x,y):
    global A1,b,a, w
    return A1*cos(pi*y/b)*sinh((pi/b)*(a/2.0-x))


def f3(x,y):
    global A2, b, a, w
    return A2*cos(3*pi*y/b)*sinh((3*pi/b)*(a/2.0-x))


def f5(x,y):
    global A3, b, a, w
    return A3*cos(5*pi*y/b)*sinh((5*pi/b)*(a/2.0-x))

def f7(x,y):
    global A4, b, a, w
    return A4*cos(7*pi*y/b)*sinh((7*pi/b)*(a/2.0-x))

def f9(x,y):
    global A5, b, a, w
    return A5*cos(9*pi*y/b)*sinh((9*pi/b)*(a/2.0-x))

x=np.linspace(x1,x2,50)

y=np.linspace(y1,y2,20)

xneu=np.linspace(x2,x3,50)
yo=np.linspace(y1,y3,20)



X, Y = np.meshgrid(x, y)
X1, Y1=np.meshgrid(xneu, y)
X2,Y2=np.meshgrid(x,yo)
X3,Y3=np.meshgrid(xneu,yo)

for i in arange(0,len(y)):
    for j in arange(0, len(x)):        
        werte[i][j]=f(y[i])

for i in arange(0, len(xneu)):
    for j in arange(0, len(y)):
        werte2[j][i]=f1(xneu[i],y[j]) + f3(xneu[i],y[j]) + f5(xneu[i],y[j]) + f7(xneu[i],y[j]) + f9(xneu[i],y[j]) 


for i in arange(0,len(yo)):
    for j in arange(0,len(x)):
        werte3[i][j]=f(y[i])


for i in arange(0, len(xneu)):
    for j in arange(0, len(yo)):
        werte4[j][i]=f1(xneu[i],yo[j]) + f3(xneu[i],yo[j]) + f5(xneu[i],yo[j]) + f7(xneu[i],yo[j]) + f9(xneu[i],yo[j])     


print(werte2)

cs = plt.contourf(X, Y, werte, 10)    
ds = plt.contourf(X1, Y1, werte2, 10)
es = plt.contourf(X2, Y2, werte3, 10)    
fs = plt.contourf(X3, Y3, werte4, 10)

plt.colorbar(cs)
#plt.colorbar(ds)

#plt.clabel(cs,inline=0, fontsize=10, colors='black')
#plt.clabel(ds,inline=0, fontsize=10, colors='black')

这是全部工作代码。我希望这能帮到别人。

你写的“彼此都很低调”,不清楚你想要什么。显示所需输出。您好@Serenity感谢您的编辑。它应该是这样的: