我正在尝试使用与Met Office相同的色阶来制作一个情节,因此我可以轻松地将我的情节与他们的情节进行比较。他们的一个例子是Here
我目前最近的努力在这里: Here
我很欣赏我的代码很乱 - 我找不到为某个阈值以上的值设置颜色的方法(否则它变成白色),因此循环。
我会上传NetCDF文件,但我没有足够高的代表来执行此操作。
许多人,非常感谢您的任何帮助。
我的绘图代码如下所示;
from Scientific.IO.NetCDF import NetCDFFile
from mpl_toolkits.basemap import Basemap
from matplotlib import pyplot as plt
import numpy as np
myfile = NetCDFFile('ERA_Dec_89-94.nc', 'r')
Lat = NetCDFFile('/home/james/Documents/Lat_Lon_NC_Files/latitudes_d02.nc','r')
Long = NetCDFFile('/home/james/Documents/Lat_Lon_NC_Files/longitudes_d02.nc','r')
XLAT = Lat.variables['XLAT'][:]
XLONG = Long.variables['XLONG'][:]
ERA_Data = myfile.variables['Monthlyrain'][:]
plot = np.zeros([1000,1730])
plot[:,:] = np.average(ERA_Data[:,:,:],axis=0)
m = Basemap(projection='merc',resolution='f',llcrnrlat=49,llcrnrlon=-11,urcrnrlat=61,urcrnrlon=3)
m.drawparallels(np.arange(-90., 91., 5.), labels=[1,0,0,0], fontsize=11)
m.drawmeridians(np.arange(-180., 181., 5.), labels=[0,0,0,1], fontsize=11)
m.drawcoastlines()
X, Y = m(XLONG, XLAT)
for i in range(0,1729):
for j in range(0,999):
if plot[j,i] >250:
plot[j,i] = 250.001
if plot[j,i] < 40:
plot[j,i] = 40
scale = [40,40.001,60,80,100,125,150,200,250, 250.001]
cs = m.contourf(X,Y,plot,scale, cmap='PuOr')
cbar = m.colorbar(cs, ticks= [40.0005,50,70,90,112.5,137.5,175,225,250.0005])
cbar.set_ticklabels(['<40','40-60', '60-80', '80-100', '100-125', '125-150', '150-200', '200-250', '>250'])
plt.title('Some Title')
cbar.set_label('Monthly average rainfall (mm)')
print "Finished"
plt.show()
答案 0 :(得分:1)
如果问题只是色彩图,您可以从屏幕上选择颜色的RGB分量并将其转换为ListedColormap
,映射到您提供的图表中的降雨边界作为示例。例如,
bounds = [0, 40, 60, 80, 100, 125, 150, 200, 250, 1000]
rgblist = [(51,0,0), (102,51,0), (153,102,51), (204,153,102), (255, 255, 255),
(204,204,255), (153,153,255), (51,102,255), (0,0,153)]
clist = [[c/255 for c in rgb] for rgb in rgblist]
from matplotlib import colors
cmap = colors.ListedColormap(clist)
norm = colors.BoundaryNorm(bounds, cmap.N)
ax.imshow(arr, cmap=cmap, norm=norm)
plt.show()
答案 1 :(得分:0)
第一部分(颜色正确)was already answered。为了将值限制在某个范围内,您有几个选项。
使用$stmt = $pdo->prepare($sql);
$stmt->execute();
$users = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($users as $user) {
echo '<tr>';
echo '<td>';
echo $user['id'];
echo '</td>';
echo '<td>';
echo $user['username'];
echo '</td>';
echo '<td>';
echo '<a href="detail.php?id=';
echo $user['id'];
echo '">';
echo 'detail';
echo '</a> ';
echo '<a href="bewerk.php?id=';
echo $user['id'];
echo '">';
echo 'bewerk';
echo '</a> ';
echo '<a href="delete.php?id=';
echo $user['id'];
echo '">';
echo 'delete';
echo '</a>';
echo '</td>';
echo '</tr>';
}
?>
和cmap.set_over
设置越界颜色,如here
使用np.clip
代替循环将值限制为certian范围:
cmap.set_under