首页 > 编程知识 正文

python安装matplotlib,matplotlib使用教程

时间:2023-05-06 20:02:36 阅读:106937 作者:4062

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 () )

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。