iammakingacolormapofa2dnumpymeshgrid :
x,y=NP.meshgrid(Fields,frequencies ) ) ) ) ) ) ) )。
cs=ax.contourf(x,y,fields_freqs_abs_grid,cmap='viridis ',N=256 ) ) )。
thevaluesinfields _ freqs _ ABS _ grid,which are plotted by color,havealreadybeenlogarithmicallyscaled。
thecolormapproducedbypython ' smatplotlibiscoarse-- itscalesover8colorseventhoughiuse ' n=256 ' forthenumberofrgbpixels . gthematlablanguageonthesamedataproducesacolormapwithsignificantlyhighercolorresolution.colormapwithsignificantlyhercorcantlyhercorcorcoresolon
The result is:
But I want the result to be:
汉克you!
解决方案
In regarding to use contourf (,I ' mnotsureifthisisaversiondependentissue,but in the most recent version,
容器(doesn ' thaveakwargforn )。
As you can see in the document,youwanttousenasarg (in syntax : contourf ) x,y,z,n ) tospecifyhowmanylevelsyouwantttoplotrattttoratttttttttoratid drawsfilledcontoursandtheresolutiondependsonthenumberoflevelstodraw.your n=256 won ' tdoanythingandcontourf (
thefollowingcodeismodifiedfromtheofficialexample,comparingresolutionswithdifferentn.incasethereisaversionissue,thiscodegodege
import numpy as np
import matplotlib.pyplot as plt
德尔塔=0.025
x=y=NP.arange (-3.0,3.01,delta ) ) ) ) ) ) ) )。
x,y=NP.meshgrid(x,y ) )。
z=10*(jqDBL ) )。
fig,(ax1,ax2 ),(ax3,ax4 ) )=PLT.subplots ) 2,2 ) ) )。
fig.set _ size _ inches (8,6 ) )。
# Your code sample
ax1.set_title(yourcodesample ) )。
ax1.set _ xlabel (word length anomaly ) )。
ax1.set _ ylabel (sentencelengthanomaly ) )。
CBAR1=fig.colorbar(cs1,ax=ax1 ) )。
# contourupton=7自动- chosen levels,
# whichshouldgivethesameasyourcode。
N=7
ax2.set_title('n=7) ) ) ) ) ) )。
ax2.set _ xlabel (word length anomaly ) )。
ax2.set _ ylabel (sentencelengthanomaly ) )。
cbar2=fig.colorbar(cs2,ax=ax2 ) ) ) ) ) ) ) ) )。
# contourupton=100自动级别。
# theresolutionisstillnotashighasusingimshow (。
N=100
CS3=ax3.contourf(x,y,z,n,cmap='viridis ' )
ax3.set_title('n=100 ' ) ) )。
ax3.set _ xlabel (word length anomaly ) )。
ax3.set _ ylabel (sentencelengthanomaly ) )。
cbar3=fig.colorbar(cs3,ax=ax3 ) ) ) ) ) ) ) ) )。
im=ax4.imshow(z,cmap='viridis ',origin='lower ',extent=(-3,-3,-3,- 3,3 ) )
ax4.set_title(atgdxxm ) )。
ax4.set _ xlabel (word length anomaly ) )。
ax4.set _ ylabel (sentencelengthanomaly ) )。
CBAR4=fig.colorbar(im,ax=ax4 ) )。
fig.tight_layout (
plt.show () )