def add_date_2d(self, x_values, y_values, z_values, dates_ticks=[], stns_ticks=[], cmap='', time_unit='month', interval="equal", value_type="raw", colorbar_max=30, colorbar_min=0, colorbar_interval=2): levels = np.linspace(colorbar_min, colorbar_max, (colorbar_max - colorbar_min) + 1) cont = Contour(self) plt.xticks(x_values[0], dates_ticks, fontsize=11) plt.yticks(zip(*y_values)[0], stns_ticks, fontproperties=font, fontsize=9) cmap = plt.get_cmap(cmap) #print z_values #print x_values #print y_values cs = cont.contour_plotting(x_values, y_values, z_values, levels, cmap) cbar = self.fig.colorbar(cs) colorbar_range = list( self.get_colorbar_range(colorbar_max, colorbar_min, colorbar_interval)) cbar.set_ticks(colorbar_range) cbar.set_ticklabels(map(str, colorbar_range))
def add_date_2d(self, x_values, y_values, z_values, dates_ticks=[], stns_ticks=[], cmap='', time_unit='month', interval="equal", value_type="raw", colorbar_max=30, colorbar_min=0, colorbar_interval=2): levels = np.linspace(colorbar_min, colorbar_max, (colorbar_max-colorbar_min)+1) cont = Contour(self) plt.xticks(x_values[0], dates_ticks, fontsize=11) plt.yticks(zip(*y_values)[0], stns_ticks, fontproperties=font, fontsize=9) cmap = plt.get_cmap(cmap) #print z_values #print x_values #print y_values cs = cont.contour_plotting(x_values, y_values, z_values, levels, cmap) cbar = self.fig.colorbar(cs) colorbar_range = list(self.get_colorbar_range(colorbar_max, colorbar_min, colorbar_interval)) cbar.set_ticks(colorbar_range) cbar.set_ticklabels(map(str, colorbar_range))
def add_map(self, values, selected_stations, map_lat_max, map_lat_min, map_lon_max, map_lon_min, color="#000000", filled=True): map = Map(self) self.fig.subplots_adjust(top=0.93) ulat, llat, ulon, llon = map_lat_max, map_lat_min, map_lon_max, map_lon_min m = Basemap(projection='merc', llcrnrlat=llat, urcrnrlat=ulat, llcrnrlon=llon, urcrnrlon=ulon, resolution='i') #cm = mpl.cm.get_cmap(self.colorbar_type) # cdict = {'red': ((0., 0, 0), (0.4, 1, 1),(0.6, 1, 1),(1, 0.5, 0.5)), # 'green': ((0., 0, 0),(0.4, 1, 1), (0.6, 1, 1), (1, 0, 0)), # 'blue': ((0., 1, 1),(0.4, 1, 1), (0.6, 1, 1), (1, 0, 0))} # cm = mpl.colors.LinearSegmentedColormap('my_colormap', cdict, 256) if 'TWN_COUNTY' in self.shapefile: m.readshapefile(self.shapefile['TWN_COUNTY']['path'], 'TWN_COUNTY', color=self.shapefile['TWN_COUNTY']['color']) if 'TWN_adm0' in self.shapefile: m.readshapefile(self.shapefile['TWN_adm0']['path'], 'TWN_adm0', color=self.shapefile['TWN_adm0']['color']) m.fillcontinents(color="#FFFFFF", zorder=0) xlist, ylist, clist, stlist = self._read_coordinate(m, values, selected_stations) s = plt.scatter(xlist, ylist, s=14, marker='x', zorder=2, color=color) m.drawmapboundary(fill_color="#F0F8FF", zorder=5) if filled: levels = np.linspace(0, 40, 41) cont = Contour(self) cm = mpl.cm.get_cmap('YlGnBu') cmap = plt.get_cmap(cm) x_min, y_min = m(map_lon_min, map_lat_min+0.0000001) x_max, y_max = m(map_lon_max, map_lat_max) x2 = np.array(np.linspace(x_min, x_max, (map_lon_max-map_lon_min)*10+1)) y2 = np.array(np.linspace(y_min, y_max, (map_lat_max-map_lat_min)*10+1)) x3, y3 = np.meshgrid(x2, y2) wait_to_fill_values = [True] * len(clist) #z_values = np.zeros((len(y2), len(x2))) z_values = np.random.randint(40, size=(len(y2), len(x2))) # 先判斷是否有在裡面 沒有的話畫空白值? # 也許不要contourf,用polygon # 內插的方法 for i, x in enumerate(x2): for j, y in enumerate(y2): for idx, value in enumerate(clist): #stlist if wait_to_fill_values[idx] and x > xlist[idx] and y> ylist[idx]: wait_to_fill_values[idx] = False z_values[j][i] = float(value) break cs = cont.contour_plotting(x3, y3, z_values, levels, cmap) cbar = self.fig.colorbar(cs) colorbar_range = list(self.get_colorbar_range(40, 0, 5)) cbar.set_ticks(colorbar_range) #cbar.set_ticklabels(map(str, colorbar_range)) # add text self._add_station_texts({'x':xlist, 'y':ylist, 'stn':stlist, 'value':clist})
def add_map(self, values, selected_stations, map_lat_max, map_lat_min, map_lon_max, map_lon_min, color="#000000", filled=True): map = Map(self) self.fig.subplots_adjust(top=0.93) ulat, llat, ulon, llon = map_lat_max, map_lat_min, map_lon_max, map_lon_min m = Basemap(projection='merc', llcrnrlat=llat, urcrnrlat=ulat, llcrnrlon=llon, urcrnrlon=ulon, resolution='i') #cm = mpl.cm.get_cmap(self.colorbar_type) # cdict = {'red': ((0., 0, 0), (0.4, 1, 1),(0.6, 1, 1),(1, 0.5, 0.5)), # 'green': ((0., 0, 0),(0.4, 1, 1), (0.6, 1, 1), (1, 0, 0)), # 'blue': ((0., 1, 1),(0.4, 1, 1), (0.6, 1, 1), (1, 0, 0))} # cm = mpl.colors.LinearSegmentedColormap('my_colormap', cdict, 256) if 'TWN_COUNTY' in self.shapefile: m.readshapefile(self.shapefile['TWN_COUNTY']['path'], 'TWN_COUNTY', color=self.shapefile['TWN_COUNTY']['color']) if 'TWN_adm0' in self.shapefile: m.readshapefile(self.shapefile['TWN_adm0']['path'], 'TWN_adm0', color=self.shapefile['TWN_adm0']['color']) m.fillcontinents(color="#FFFFFF", zorder=0) xlist, ylist, clist, stlist = self._read_coordinate( m, values, selected_stations) s = plt.scatter(xlist, ylist, s=14, marker='x', zorder=2, color=color) m.drawmapboundary(fill_color="#F0F8FF", zorder=5) if filled: levels = np.linspace(0, 40, 41) cont = Contour(self) cm = mpl.cm.get_cmap('YlGnBu') cmap = plt.get_cmap(cm) x_min, y_min = m(map_lon_min, map_lat_min + 0.0000001) x_max, y_max = m(map_lon_max, map_lat_max) x2 = np.array( np.linspace(x_min, x_max, (map_lon_max - map_lon_min) * 10 + 1)) y2 = np.array( np.linspace(y_min, y_max, (map_lat_max - map_lat_min) * 10 + 1)) x3, y3 = np.meshgrid(x2, y2) wait_to_fill_values = [True] * len(clist) #z_values = np.zeros((len(y2), len(x2))) z_values = np.random.randint(40, size=(len(y2), len(x2))) # 先判斷是否有在裡面 沒有的話畫空白值? # 也許不要contourf,用polygon # 內插的方法 for i, x in enumerate(x2): for j, y in enumerate(y2): for idx, value in enumerate(clist): #stlist if wait_to_fill_values[ idx] and x > xlist[idx] and y > ylist[idx]: wait_to_fill_values[idx] = False z_values[j][i] = float(value) break cs = cont.contour_plotting(x3, y3, z_values, levels, cmap) cbar = self.fig.colorbar(cs) colorbar_range = list(self.get_colorbar_range(40, 0, 5)) cbar.set_ticks(colorbar_range) #cbar.set_ticklabels(map(str, colorbar_range)) # add text self._add_station_texts({ 'x': xlist, 'y': ylist, 'stn': stlist, 'value': clist })