为什么SymLogNorm在使用等值线图时没有创建正确的图?

时间:2013-11-20 11:01:11

标签: python matplotlib plot matplotlib-basemap

在mpl_toolkits.basemap中使用SymLogNorm部分时遇到一些问题。我想要一个对数刻度轮廓图,在对数刻度中具有负值和正值(因此使用SymLogNorm)。但是,每当我使用它时,我得到的图表只显示正值和负值(见下文)。使用散点图示例时,它可以正常工作,但在地图上绘图时则无效。

image

如何将其提供给我需要的任何帮助都会受到极大关注。

干杯

import matplotlib.pyplot as plt
import matplotlib.cm as cm
import matplotlib as mpl
import numpy as np
from mpl_toolkits.basemap import Basemap

lon = [-180,-140,-100,-60,-20,0,20,60,100,140,180]
lat = [90,70,50,30,10,-10,-30,-50,-70,-90]
bc = [[1,4,5,5,5,4,0.1,-0.2,-0.03,0,1],[0.1,1,1,0.8,-0.6,-0.005,0,0,-0.9,-0.004,-0.5],[0.7,0.07,0,0,0,0.6,0.1,-2.3,1,1,1.5],[1,1,0,-0.1,0,-0.5,1,1.2,2,11,3],[1,4,5,5,5,4,0.1,-0.2,-0.03,0,-0.9],[0.1,1,1,0.8,-0.6,-0.005,0,0,-0.9,-0.004,-0.08],[0.7,0.07,0,0,0,0.6,0.1,-2.3,1,1,0],[1,1,0,-0.1,0,-0.5,1,1.2,2,11,3],[1,1,0,-0.1,0,-0.5,1,1.2,2,11,2],[1,1,0,-0.1,0,-0.5,1,1.2,3,0,0.3]]
 #Draw Map
    # use low resolution coastlines.
map = Basemap(projection='cyl',lat_0=0.,lon_0=0,resolution='l')
    # draw coastlines, country boundaries, fill continents.
map.drawcoastlines(linewidth=0.75)
map.drawcountries(linewidth=0.25)
map.fillcontinents #(color='grey',lake_color='white')
# draw the edge of the map projection region 
map.drawmapboundary(fill_color='white')
    #draw lat/lon grid lines every 30 degrees.
map.drawmeridians(np.arange(-180,180,30)) 
map.drawparallels(np.arange(-90,90,30))

    #map completed, now ask which month you want data for
    #make grid on world map from the long/lat in the data (shape of bc)

lon, lat = np.meshgrid(lon, lat)    
    #make those the x and y axis, but in map form
x, y =map(lon,lat)


    #Clear plot and choose colour maps
plt.clf()
my_cmap = cm.get_cmap('brg')
tickld = [-10,-1,-1e-1,-1e3,1e3,1e-1,1,10]
norm=mpl.colors.SymLogNorm(linthresh=1e-4, vmin=-100, vmax=100)
#plot the filled contour map, using levels, colours and a log scale for the     colourbar
cs = map.contourf(x,y,bc,levels=tickld,cmap=my_cmap,norm = norm)

    #create the colour bounds for the colour map (same as for the plot)


cb1 = plt.colorbar(cmap=my_cmap, 
        norm=norm,
        extend='both',
        orientation="vertical",
        ticks=tickld,
        shrink = 0.38,
        fraction = 0.01)



    #add coastlines on top of plot
map.drawcoastlines(linewidth=0.75)
map.drawcountries(linewidth=0.25)
    #show plot
plt.show()

1 个答案:

答案 0 :(得分:0)

问题解决了!!!

SymLogNorm不喜欢使用指数负数作为阈值。

为了解决这个问题,而不是像1e-4这样的东西,而是放入0.0001。

简单但又令人沮丧!

相关问题