matplotlib pcolormesh返回Flat contour

时间:2018-02-09 19:28:34

标签: matplotlib plot mesh contour

以下是我对轮廓图的输入。即使z中的值不同,它也会返回具有平面轮廓的图。我正在使用python3。

import matplotlib.pyplot as plt
import matplotlib.colors as colors
import matplotlib.cm as cmx
import matplotlib as mpl

x = [8,10,12,14,16,18,20]
y = [ 0.4,0.45,0.5, 0.55, 0.6,0.65,0.7, 0.75,0.8,0.85,0.9,0.95,1.,1.05,1.1 ,1.15, 1.2 ]
z= [[  1.78963157e-05,   1.61644497e-05,   1.82095363e-05,   1.68437063e-05,     1.72978900e-05,   1.32008829e-05,   1.34279038e-05],
[ -6.88334562e-07,  -1.36603740e-06,  -4.87142628e-05,  -3.72777265e-04,    -1.13885082e-03,  -2.21202558e-03,  -3.04815629e-03],
[ -2.75334480e-06,  -1.69193652e-04,  -3.32760366e-03,  -1.41131639e-02,    -3.22716385e-02,  -5.08755872e-02,  -6.43446161e-02] ,
[ -1.99621453e-05,  -6.62870148e-03,  -5.51200368e-02,  -1.46310900e-01,   -2.50479130e-01,  -3.44686045e-01,  -4.14010369e-01],
[ -8.05638699e-04,  -6.86469566e-02,  -3.09807186e-01,  -5.95417818e-01,    -8.70429863e-01,  -1.10896694e+00,  -1.28863817e+00],
[ -1.09028691e-02,  -2.86631096e-01,  -8.72346699e-01,  -1.38425321e+00,    -1.83269423e+00,  -2.21171217e+00,  -2.49614674e+00],
[ -5.44918164e-02,  -7.04700599e-01,  -1.61944488e+00,  -2.23166225e+00,    -2.70610186e+00,  -3.05736645e+00,  -3.31027451e+00],
[ -1.46581196e-01,  -1.27933729e+00,  -2.34440457e+00,  -2.90545526e+00,    -3.30654522e+00,  -3.61596075e+00,  -3.81523854e+00],
[ -2.83847825e-01,  -1.94187773e+00,  -2.97264260e+00,  -3.53393575e+00,    -3.91886829e+00,  -4.39978913e+00,  -4.40556012e+00],
[ -4.52972035e-01,  -2.60277547e+00,  -3.69173458e+00,  -6.28054855e+00,    -6.28057405e+00,  -6.28058156e+00,  -6.28059977e+00],
[ -6.52260330e-01,  -3.24424411e+00,  -6.28054559e+00,  -4.23917726e+00,   -3.53008773e+00,  -3.57473901e+00,  -3.51794282e+00],
[ -8.83887486e-01,  -4.43537561e+00,  -3.81221898e+00,  -2.95280246e+00,    -2.74353298e+00,  -2.75130073e+00,  -2.76171281e+00],
[ -1.14292285e+00,  -6.28045385e+00,  -2.91582775e+00,  -2.43497586e+00,    -2.34172630e+00,  -2.35585837e+00,  -2.33020785e+00],
[ -1.48005357e+00,  -3.32913613e+00,  -2.51281694e+00,  -2.22591860e+00,    -2.20713439e+00,  -2.18431855e+00,  -2.15543300e+00],
[ -1.95083193e+00,  -2.84478852e+00,  -2.30980115e+00,  -2.17543461e+00,    -2.18077741e+00,  -2.15239738e+00,  -2.12150557e+00],
[ -2.67504634e+00,  -2.47989403e+00,  -2.17826984e+00,  -2.13298637e+00,    -2.14346365e+00,  -2.13308098e+00,  -2.11940317e+00],
[ -6.27708545e+00,  -2.24516401e+00,  -2.07349772e+00,  -2.04499101e+00,    -2.07452620e+00,  -2.07811441e+00,  -2.08486007e+00]]

fig,ax = plt.subplots()
cmap=plt.cm.bwr
ax.pcolormesh(x, y, z, cmap=cmap, rasterized=True, norm=mpl.colors.Normalize(vmin=-6,vmax=0))

这就是我得到的: enter image description here

1 个答案:

答案 0 :(得分:0)

发现它!我正在创建x列表,但它没有排序。 8位于列表的末尾。所以我得到了一个平坦的情节。现在我对x和y参数进行排序,并且它正在工作。我希望这个答案可以帮助其他人节省一些时间:)