我正在使用matplotlib,我希望在pcolormesh的顶部绘制一个contourf,并在描述的同时显示两者。这是代码:
"""space for module inclusion"""
fig, ax = plt.subplots()
ax.pcolormesh(*arguments here*)
ax.contour(*arguments here*)
plt.show()
但是,当我尝试显示数据时,只显示contourf(覆盖pcolormesh)。关于这个的任何想法?
EDIT_1:
基本上我正在使用的值如下:
X:
[ 63.37480164 63.37519836 63.37559891 63.37599945 63.37639999
63.37680054 63.37720108 63.37760162 63.37799835 63.3783989
63.37879944 63.37919998 63.37960052 63.38000107 63.38040161
63.38079834 63.38119888 63.38159943 63.38199997 63.38240051
63.38280106 63.3832016 63.38359833 63.38399887 63.38439941
63.38479996 63.3852005 63.38560104 63.38600159 63.38639832
63.38679886 63.3871994 63.38759995 63.38800049 63.38840103
63.38880157 63.3891983 63.38959885 63.38999939 63.39039993
63.39080048 63.39120102 63.39160156 63.39199829 63.39239883
63.39279938 63.39319992 63.39360046 63.39400101 63.39440155
63.39479828 63.39519882 63.39559937 63.39599991 63.39640045
63.39680099 63.39720154 63.39759827 63.39799881 63.39839935
63.3987999 63.39920044 63.39960098 63.40000153 63.40039825
63.4007988 63.40119934 63.40159988 63.40200043 63.40240097
63.40280151 63.40319824 63.40359879 63.40399933 63.40439987
63.40480042 63.40520096 63.4056015 63.40599823 63.40639877
63.40679932 63.40719986 63.4076004 63.40800095 63.40840149
63.40879822 63.40919876 63.4095993 63.40999985 63.41040039
63.41080093 63.41120148 63.41159821 63.41199875 63.41239929
63.41279984 63.41320038 63.41360092 63.41400146 63.41439819
63.41479874 63.41519928 63.41559982 63.41600037 63.41640091
63.41680145 63.41719818 63.41759872 63.41799927 63.41839981
63.41880035 63.4192009 63.41960144 63.41999817 63.42039871
63.42079926 63.4211998 63.42160034 63.42200089 63.42240143
63.42279816 63.4231987 63.42359924 63.42399979 63.42440033
63.42480087 63.42520142 63.42559814 63.42599869 63.42639923
63.42679977 63.42720032 63.42760086 63.4280014 63.42839813
63.42879868 63.42919922 63.42959976 63.43000031 63.43040085
63.43080139 63.43119812 63.43159866 63.43199921 63.43239975
63.43280029 63.43320084 63.43360138 63.43399811 63.43439865
63.43479919 63.43519974 63.43560028 63.43600082 63.43640137
63.4367981 63.43719864 63.43759918 63.43799973 63.43840027
63.43880081 63.43920135 63.4396019 63.43999863 63.44039917
63.44079971 63.44120026 63.4416008 63.44200134 63.44240189
63.44279861 63.44319916 63.4435997 63.44400024 63.44440079
63.44480133 63.44520187 63.4455986 63.44599915 63.44639969
63.44680023 63.44720078 63.44760132 63.44800186 63.44839859
63.44879913 63.44919968 63.44960022 63.45000076 63.45040131
63.45080185 63.45119858 63.45159912 63.45199966 63.45240021
63.45280075 63.45320129 63.45360184 63.45399857 63.45439911
63.45479965 63.4552002 63.45560074 63.45600128 63.45640182
63.45679855 63.4571991 63.45759964 63.45800018 63.45840073
63.45880127 63.45920181 63.45959854 63.45999908 63.46039963
63.46080017 63.46120071 63.46160126 63.4620018 63.46239853
63.46279907 63.46319962 63.46360016 63.4640007 63.46440125
63.46480179 63.46519852 63.46559906 63.4659996 63.46640015
63.46680069 63.46720123 63.46760178 63.4679985 63.46839905
63.46879959 63.46920013 63.46960068 63.47000122 63.47040176
63.47079849 63.47119904 63.47159958 63.47200012 63.47240067
63.47280121 63.47320175 63.47359848 63.47399902 63.47439957
63.47480011 63.47520065 63.4756012 63.47600174 63.47639847
63.47679901 63.47719955 63.4776001 63.47800064 63.47840118
63.47880173 63.47919846 63.479599 63.47999954 63.48040009
63.48080063 63.48120117 63.48160172 63.48199844 63.48239899
63.48279953 63.48320007 63.48360062 63.48400116 63.4844017
63.48479843 63.48519897 63.48559952 63.48600006 63.4864006
63.48680115 63.48720169 63.48759842 63.48799896 63.48839951
63.48880005 63.48920059 63.48960114 63.49000168 63.49039841
63.49079895 63.49119949 63.49160004 63.49200058 63.49240112
63.49280167 63.49319839 63.49359894 63.49399948 63.49440002
63.49480057 63.49520111 63.49560165 63.49599838 63.49639893
63.49679947 63.49720001 63.49760056 63.4980011 63.49840164
63.49879837 63.49919891 63.49959946 63.5 63.50040054
63.50080109 63.50120163 63.50159836 63.5019989 63.50239944
63.50279999 63.50320053 63.50360107 63.50400162 63.50439835
63.50479889 63.50519943 63.50559998 63.50600052 63.50640106
63.50680161 63.50719833 63.50759888 63.50799942 63.50839996
63.50880051 63.50920105 63.50960159 63.50999832 63.51039886
63.51079941 63.51119995 63.51160049 63.51200104 63.51240158
63.51279831 63.51319885 63.5135994 63.51399994 63.51440048
63.51480103 63.51520157 63.5155983 63.51599884 63.51639938
63.51679993 63.51720047 63.51760101 63.51800156 63.51839828
63.51879883 63.51919937 63.51959991 63.52000046 63.520401
63.52080154 63.52119827 63.52159882 63.52199936 63.5223999
63.52280045 63.52320099 63.52360153 63.52399826 63.5243988
63.52479935 63.52519989 63.52560043 63.52600098 63.52640152
63.52679825 63.52719879 63.52759933 63.52799988 63.52840042
63.52880096 63.52920151 63.52959824 63.52999878 63.53039932
63.53079987 63.53120041 63.53160095 63.5320015 63.53239822
63.53279877 63.53319931 63.53359985 63.5340004 63.53440094
63.53480148 63.53519821 63.53559875 63.5359993 63.53639984
63.53680038 63.53720093 63.53760147 63.5379982 63.53839874
63.53879929 63.53919983 63.53960037 63.54000092 63.54040146
63.54079819 63.54119873 63.54159927 63.54199982 63.54240036
63.5428009 63.54320145 63.54359818 63.54399872 63.54439926
63.5447998 63.54520035 63.54560089 63.54600143 63.54639816
63.54679871 63.54719925 63.54759979 63.54800034 63.54840088
63.54880142 63.54919815 63.54959869 63.54999924 63.55039978
63.55080032 63.55120087 63.55160141 63.55199814 63.55239868
63.55279922 63.55319977 63.55360031 63.55400085 63.5544014
63.55479813 63.55519867 63.55559921 63.55599976 63.5564003
63.55680084 63.55720139 63.55759811 63.55799866 63.5583992
63.55879974 63.55920029 63.55960083 63.56000137 63.5603981
63.56079865 63.56119919 63.56159973 63.56200027 63.56240082
63.56280136 63.5632019 63.56359863 63.56399918 63.56439972
63.56480026 63.56520081 63.56560135 63.56600189 63.56639862
63.56679916 63.56719971 63.56760025 63.56800079 63.56840134
63.56880188 63.56919861 63.56959915 63.56999969 63.57040024
63.57080078 63.57120132 63.57160187 63.5719986 63.57239914
63.57279968 63.57320023 63.57360077 63.57400131 63.57440186
63.57479858 63.57519913 63.57559967 63.57600021 63.57640076
63.5768013 63.57720184 63.57759857 63.57799911 63.57839966
63.5788002 63.57920074 63.57960129 63.58000183 63.58039856
63.5807991 63.58119965 63.58160019 63.58200073 63.58240128
63.58280182 63.58319855 63.58359909 63.58399963 63.58440018
63.58480072 63.58520126 63.58560181 63.58599854 63.58639908
63.58679962 63.58720016 63.58760071 63.58800125 63.58840179
63.58879852 63.58919907 63.58959961 63.59000015 63.5904007
63.59080124 63.59120178 63.59159851 63.59199905 63.5923996
63.59280014 63.59320068 63.59360123 63.59400177 63.5943985
63.59479904 63.59519958 63.59560013 63.59600067 63.59640121
63.59680176 63.59719849 63.59759903 63.59799957 63.59840012
63.59880066 63.5992012 63.59960175 63.59999847 63.60039902
63.60079956 63.6012001 63.60160065 63.60200119 63.60240173
63.60279846 63.60319901 63.60359955 63.60400009 63.60440063
63.60480118 63.60520172 63.60559845 63.60599899 63.60639954
63.60680008 63.60720062 63.60760117 63.60800171 63.60839844
63.60879898 63.60919952 63.60960007 63.61000061 63.61040115
63.6108017 63.61119843 63.61159897 63.61199951 63.61240005
63.6128006 63.61320114 63.61360168 63.61399841 63.61439896
63.6147995 63.61520004 63.61560059 63.61600113 63.61640167
63.6167984 63.61719894 63.61759949 63.61800003 63.61840057
63.61880112 63.61920166 63.61959839 63.61999893 63.62039948
63.62080002 63.62120056 63.6216011 63.62200165 63.62239838
63.62279892 63.62319946 63.62360001 63.62400055 63.62440109
63.62480164 63.62519836 63.62559891 63.62599945 63.62639999
63.62680054 63.62720108 63.62760162 63.62799835 63.6283989
63.62879944 63.62919998 63.62960052 63.63000107 63.63040161
63.63079834 63.63119888 63.63159943 63.63199997 63.63240051
63.63280106 63.6332016 63.63359833 63.63399887 63.63439941
63.63479996 63.6352005 63.63560104 63.63600159 63.63639832
63.63679886 63.6371994 63.63759995 63.63800049 63.63840103
63.63880157 63.6391983 63.63959885 63.63999939 63.64039993
63.64080048 63.64120102 63.64160156 63.64199829 63.64239883
63.64279938 63.64319992 63.64360046 63.64400101 63.64440155
63.64479828 63.64519882 63.64559937 63.64599991 63.64640045
63.64680099 63.64720154 63.64759827 63.64799881 63.64839935
63.6487999 63.64920044 63.64960098 63.65000153 63.65039825
63.6507988 63.65119934 63.65159988 63.65200043 63.65240097
63.65280151 63.65319824 63.65359879 63.65399933 63.65439987
63.65480042 63.65520096 63.6556015 63.65599823 63.65639877
63.65679932 63.65719986 63.6576004 63.65800095 63.65840149
63.65879822 63.65919876 63.6595993 63.65999985 63.66040039
63.66080093 63.66120148 63.66159821 63.66199875 63.66239929
63.66279984]
Y:
[[ 2.49405336 2.49405479 2.49405622 ..., 2.49506283 2.49506426
2.49506545]
[ 2.50891113 2.50891256 2.50891399 ..., 2.50994205 2.50994349
2.50994492]
[ 2.52241206 2.52241349 2.52241492 ..., 2.52346492 2.52346635
2.52346778]
...,
[ 3.86142349 3.8614254 3.86142731 ..., 3.86282992 3.86283183
3.86283374]
[ 3.87396121 3.87396312 3.87396502 ..., 3.87538362 3.87538576
3.87538767]
[ 3.88761282 3.88761473 3.88761663 ..., 3.8890295 3.88903141
3.88903356]]
Z:
[[ 1.17835083e+03 1.18324207e+03 1.19204639e+03 ..., -5.34249163e+00
5.41835642e+00 3.46183872e+00]
[ 1.25111658e+03 1.24381042e+03 1.25598743e+03 ..., 1.37508184e-01
2.57289410e+00 -3.10967302e+00]
[ 1.31315002e+03 1.30969629e+03 1.30394031e+03 ..., 3.06716180e+00
7.64734685e-01 -9.59618759e+00]
...,
[ 3.51441078e+01 3.44107513e+01 3.44107513e+01 ..., -5.19034863e+00
-1.89025664e+00 -4.45699453e+00]
[ 2.77138577e+01 2.72105122e+01 2.67071648e+01 ..., -1.48025024e+00
5.33136606e-01 -9.76903498e-01]
[ 2.52477798e+01 2.67249184e+01 2.82020588e+01 ..., 1.36409312e-01
-2.32875556e-01 -2.07929993e+00]]
,代码如下:
fig,ax = plt.subplots()
ax.pcolormesh(x,y,z, cmap='gist_rainbow', linewidth=0, zorder=1)
#plt.set_xlabel('Time [s]')
#plt.set_ylabel('R [m]; ECE')
#plt.view_init(90,-90)
#plt.set_axis_off()
ax.contour(z,zorder=2)
plt.show()
输出:http://www.image-upload.net/di/4T7EQ1AJ/Capture.png
另一个代码:
fig,ax = plt.subplots()
#ax.pcolormesh(x,y,z, cmap='gist_rainbow', linewidth=0, zorder=1)
#plt.set_xlabel('Time [s]')
#plt.set_ylabel('R [m]; ECE')
#plt.view_init(90,-90)
#plt.set_axis_off()
print x
print "\n\n"
print y
print "\n\n"
print z
ax.contour(z,zorder=2)
plt.show()
输出:http://www.image-upload.net/di/4T7EQ1AJ/Capture.png
最后,这段代码
fig,ax = plt.subplots()
ax.pcolormesh(x,y,z, cmap='gist_rainbow', linewidth=0, zorder=1)
#plt.set_xlabel('Time [s]')
#plt.set_ylabel('R [m]; ECE')
#plt.view_init(90,-90)
#plt.set_axis_off()
print x
print "\n\n"
print y
print "\n\n"
print z
#ax.contour(z,zorder=2)
plt.show()
输出:http://www.image-upload.net/di/JEKL/Capture.png
我想要的是这个轮廓http://www.image-upload.net/di/4T7EQ1AJ/Capture.png位于http://www.image-upload.net/di/JEKL/Capture.png之上,没有凌乱的白色背景! :)
答案 0 :(得分:1)
Contourf是一个填充轮廓。所以它掩盖了它下面的一切。那么有两种选择:
1)您可以尝试在contourf中设置alpha ...即alpha = 0.25。这将使填充的轮廓部分透视。
2)更好的选择:使用轮廓而不是轮廓f,然后只绘制轮廓线。
答案 1 :(得分:0)
您只需要使用zorder
来控制艺术家的呈现顺序(哪些元素具有较高zorder
'以上'元素较低zorder
)
fig, ax = plt.subplots()
ax.pcolormesh(..., zorder=1)
ax.contour(..., zorder=2)
plt.show()