matplotlib-basemap

Using pcolormesh for plotting an orbit data

痴心易碎 提交于 2019-11-29 05:14:37
I am trying to map a dataset with associated latitude and longitude. The details of the data I am using are given below: Variable Type Data/Info ------------------------------- lat ndarray 1826x960, type `float64` lon ndarray 1826x960, type `float64` data ndarray 1826x960, type `float64` I have created then a basemap: m = Basemap(projection='cyl', llcrnrlon=-180, urcrnrlon=180, llcrnrlat=-40, urcrnrlat=40, resolution='c') Now, on the basemap created, I'd plot the above mentioned dataset using pcolormesh: m.drawcoastlines() m.drawcountries x,y = m(lon,lat) m.pcolormesh(x,y,data) m.colorbar()

Basemap library using Anaconda Jupyter Notebooks - KeyError: PROJ_LIB

喜欢而已 提交于 2019-11-29 03:55:45
I'm trying to install and import the Basemap library into my Jupyter Notebook, but this returns the following error: KeyError: 'PROJ_LIB' After some research online, I understand I'm to install Basemap on a separate environment in Anaconda. After creating a new environment and installing Basemap (as well as all other relevant libraries), I have activated the environment. But when importing Basemap I still receive the same KeyError. Here's what I did in my MacOS terminal: conda create --name Py3.6 python=3.6 basemap source activate Py3.6 conda upgrade proj4 env | grep -i proj conda update -

How to insert scale bar in a map in matplotlib

一曲冷凌霜 提交于 2019-11-29 03:38:34
Any ideas on how can I insert a scale bar in a map in matplotlib that shows the length scale? something like the one I have attached. Or maybe any ideas on measuring and showing distances automatically (not drawing an arrow and writing the distance manually!)? Thanks :) There is a an already existing class for scalebars in matplotlib called AnchoredSizeBar . In the below example AnchoredSizeBar is used to add a scalebar to an image (or map over a 100x100 meter area of randomness). import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1.anchored_artists import

Is it possible to control matplotlib marker orientation?

大城市里の小女人 提交于 2019-11-28 23:18:30
I would like to know if I have a triangular marker, is it possible to control its orientation? I have a series of facets, with their corresponding vertices, and I would like to plot a basemap of them. I know it is straight forward script when using Mayavi and tvtk.PolyData. But since I'm dealing with maps and not 3D objects, things got a bit complicated. ps: for maps I'm using basemap tool. I thanks for any help. You can create custom polygons using the keyword argument marker and passing it a tuple of 3 numbers (number of sides, style, rotation) . To create a triangle you would use (3, 0,

Draw polygons more efficiently with matplotlib

*爱你&永不变心* 提交于 2019-11-28 18:20:10
I have a dateset of around 60000 shapes (with lat/lon coordinates of each corner) which I want to draw on a map using matplotlib and basemap. This is the way I am doing it at the moment: for ii in range(len(data)): lons = np.array([data['lon1'][ii],data['lon3'][ii],data['lon4'][ii],data['lon2'][ii]],'f2') lats = np.array([data['lat1'][ii],data['lat3'][ii],data['lat4'][ii],data['lat2'][ii]],'f2') x,y = m(lons,lats) poly = Polygon(zip(x,y),facecolor=colorval[ii],edgecolor='none') plt.gca().add_patch(poly) However, this takes around 1.5 minutes on my machine and I was thinking whether it is

Plot GDAL raster using matplotlib Basemap

笑着哭i 提交于 2019-11-28 17:59:34
I would like to plot a raster tiff ( download -723Kb) using matplotlib Basemap. My raster's projection coordinates is in meter: In [2]: path = r'albers_5km.tif' raster = gdal.Open(path, gdal.GA_ReadOnly) array = raster.GetRasterBand(20).ReadAsArray() print ('Raster Projection:\n', raster.GetProjection()) print ('Raster GeoTransform:\n', raster.GetGeoTransform()) Out [2]: Raster Projection: PROJCS["unnamed",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY

Drawing a graph with NetworkX on a Basemap

依然范特西╮ 提交于 2019-11-28 16:54:57
I want to plot a graph on a map where the nodes would be defined by coordinates (lat, long) and have some value associated. I have been able to plot points as a scatterplot on a basemap but can't seem to find how to plot a graph on the map. Thanks. EDIT : I have added code on how I plotted the points on a basemap. Most of it has been adapted from code in this article. from mpl_toolkits.basemap import Basemap from shapely.geometry import Point, MultiPoint import pandas as pd import matplotlib.pyplot as plt m = Basemap( projection='merc', ellps = 'WGS84', llcrnrlon=-130, llcrnrlat=25, urcrnrlon=

IndexError with Basemap.contour() when using certain projections

心已入冬 提交于 2019-11-28 14:24:52
I have run into problems when using Basemap.contour with certain projections. Based on the example given in the Basemap documentation , I created the following working code which produces the expected result. The example uses the 'tmerc' projection. from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np m2 = Basemap(projection='tmerc', lat_0=0, lon_0=3, llcrnrlon=1.819757266426611, llcrnrlat=41.583851612359275, urcrnrlon=1.841589961763497, urcrnrlat=41.598674173123) ##m2 = Basemap(projection='kav7',lon_0=0) x = np.linspace(0, m2.urcrnrx, 100) y = np

scatter plot data does not appear on continents in 'hammer' basemap

帅比萌擦擦* 提交于 2019-11-28 13:46:30
I am attempting to plot a dataset over the 'hammer' basemap using a scatter plot. However, the data points won't plot on top of the continents. I noticed in the matplotlib example , there is also not data on the continents (I assumed this was due to the nature of the example). I'm wondering if I'm doing something wrong, or if data cannot be plotted on top of the continents using 'hammer' by design. If this is the case, is there an ideal basemap to use to plot scatter plot data over the whole Earth (using a relief map would be great, but I would settle for anything at this point)? You're

How to draw rectangles on a Basemap

青春壹個敷衍的年華 提交于 2019-11-28 08:27:01
I'm looking for a way to plot filled rectangles on a Basemap. I could easily draw the rectangle's edges using the drawgreatcircle method, but I cannot find a way to actually fill these rectangles (specifying color and alpha). You can add a matplotlib.patches.Polygon() directly to your axes. The question is whether you want your rectangles defined the plot coordinates (straight lines on the plot) or in map coordinates (great circles on the plot). Either way, you specify vertices in map coordinates and then transform them to plot coordinates by calling the Basemap instance ( m() in the below