matplotlib-basemap

Python real time varying heat map plotting

一世执手 提交于 2019-11-30 15:46:28
I have a 2D grid 50*50. For each location I have an intensity value(i.e data is like (x,y,intensity) for each of those 50*50 locations). I would like to visualize the data as a heatmap. The twist is that every second the intensity will change(for most of the locations), which means I will need to re-draw the heatmap every second. I am wondering what is the best library/approach to handle this kind of real-time varing heatmap. This really depends on how you get your data, but: import matplotlib.pyplot as plt import numpy as np import time # create the figure fig = plt.figure() ax = fig.add

Regridding regular netcdf data

冷暖自知 提交于 2019-11-30 10:33:34
I have a netcdf file containing global sea-surface temperatures. Using matplotlib and Basemap, I've managed to make a map of this data, with the following code: from netCDF4 import Dataset import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.basemap import Basemap filename = '/Users/Nick/Desktop/SST/SST.nc' fh = Dataset(filename, mode='r') lons = fh.variables['LON'][:] lats = fh.variables['LAT'][:] sst = fh.variables['SST'][:].squeeze() fig = plt.figure() m = Basemap(projection='merc', llcrnrlon=80.,llcrnrlat=-25.,urcrnrlon=150.,urcrnrlat=25.,lon_0=115., lat_0=0., resolution='l

how to mask the specific array data based on the shapefile

僤鯓⒐⒋嵵緔 提交于 2019-11-30 10:12:28
Here is my question: the 2-d numpy array data represent some property of each grid space the shapefile as the administrative division of the study area(like a city). For example: http://i4.tietuku.com/84ea2afa5841517a.png The whole area has 40x40 grids network, and I want to extract the data inside the purple area. In other words , I want to mask the data outside the administrative boundary into np.nan. My early attempt I label the grid number and select the specific array data into np.nan. http://i4.tietuku.com/523df4783bea00e2.png value[0,:] = np.nan value[1,:] = np.nan . . . . Can Someone

3D CartoPy similar to Matplotlib-Basemap

ε祈祈猫儿з 提交于 2019-11-30 09:56:42
I'm new to Python with a question about Cartopy being able to be used in a 3D plot. Below is an example using matplotlibBasemap . import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from mpl_toolkits.basemap import Basemap m = Basemap(projection='merc', llcrnrlat=52.0,urcrnrlat=58.0, llcrnrlon=19.0,urcrnrlon=40.0, rsphere=6371200.,resolution='h',area_thresh=10) fig = plt.figure() ax = Axes3D(fig) ax.add_collection3d(m.drawcoastlines(linewidth=0.25)) ax.add_collection3d(m.drawcountries(linewidth=0.35)) ax.add_collection3d(m.drawrivers(color='blue')) ax.set_xlabel('X') ax.set

Python and Matplotlib and Annotations with Mouse Hover

谁说胖子不能爱 提交于 2019-11-30 05:25:43
I am currently employing this code to have pop up annotatations on a map when i click on a point in a Basemap Matplotlib Plot. dcc = DataCursor(self.figure.gca()) self.figure.canvas.mpl_connect('pick_event',dcc) plot_handle.set_picker(5) self.figure.canvas.draw() class DataCursor(object): import matplotlib.pyplot as plt text_template = 'x: %0.2f\ny: %0.2f' x, y = 0.0, 0.0 xoffset, yoffset = -20 , 20 text_template = 'A: %s\nB: %s\nC: %s' def __init__(self, ax): self.ax = ax self.annotation = ax.annotate(self.text_template, xy=(self.x, self.y), xytext=(0,0), textcoords='axes fraction', ha='left'

Regridding regular netcdf data

我与影子孤独终老i 提交于 2019-11-29 15:45:01
问题 I have a netcdf file containing global sea-surface temperatures. Using matplotlib and Basemap, I've managed to make a map of this data, with the following code: from netCDF4 import Dataset import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.basemap import Basemap filename = '/Users/Nick/Desktop/SST/SST.nc' fh = Dataset(filename, mode='r') lons = fh.variables['LON'][:] lats = fh.variables['LAT'][:] sst = fh.variables['SST'][:].squeeze() fig = plt.figure() m = Basemap

how to mask the specific array data based on the shapefile

…衆ロ難τιáo~ 提交于 2019-11-29 15:21:12
问题 Here is my question: the 2-d numpy array data represent some property of each grid space the shapefile as the administrative division of the study area(like a city). For example: http://i4.tietuku.com/84ea2afa5841517a.png The whole area has 40x40 grids network, and I want to extract the data inside the purple area. In other words , I want to mask the data outside the administrative boundary into np.nan. My early attempt I label the grid number and select the specific array data into np.nan.

Filling shapefile polygons with a color in matplotlib

女生的网名这么多〃 提交于 2019-11-29 12:24:38
I am searching way to fill polygons of a shapefile based on a value. So far from basemap tutorial ( http://basemaptutorial.readthedocs.io/en/latest/shapefile.html ) i 've found how to fill the polygons with a specific color. import matplotlib.pyplot as plt import pypyodbc from mpl_toolkits.basemap import Basemap from matplotlib.patches import Polygon from matplotlib.collections import PatchCollection from matplotlib.patches import PathPatch import numpy as np fig= plt.figure() ax= fig.add_subplot(111) m=Basemap(projection='cyl',llcrnrlat=34.5,llcrnrlon=19,urcrnrlat=42,urcrnrlon=28.5,resolution

OSError geos_c could not be found when Installing Shapely

冷暖自知 提交于 2019-11-29 09:13:14
I'm a newbie to making/plotting on maps with python, been trying to follow this blogpost to generate a world map (http://sciblogs.co.nz/seeing-data/2011/08/12/plotting-geographic-data-on-a-world-map-with-python/). Got stuck with a few things here: Installing Basemap (a Matplotlib extension for plotting data on geographic projections). from mpl_toolkits.basemap import Basemap Traceback (most recent call last): File "geos_demo.py", line 1, in <module> from mpl_toolkits.basemap import Basemap ImportError: No module named mpl_toolkits.basemap Install Shapely, but the following error occurs [1]:

Matplotlib Basemap animation

泄露秘密 提交于 2019-11-29 08:29:18
I'm using basemap to plot some points on a map, and I want to add any kind of animation to it. It could literally serve no purpose at all, as long as it is an animation it would be nice. This is what I currently have to make the map, from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np import matplotlib.animation as animation map = Basemap(projection='robin', resolution = 'l', area_thresh = 1000.0, lat_0=0, lon_0=-130) map.drawcoastlines() map.drawcountries() map.fillcontinents(color = 'gray') map.drawmapboundary() map.drawmeridians(np.arange(0, 360, 30))