Trouble with basemap subplots

2024/10/5 19:21:14

I need to make a plot with n number of basemap subplots. But when I am doing this the all the values are plotted on the first subplot.

My data is a set of 'n' matrixes, stored in data_all.

f, map = plt.subplots(n,sharex=True, sharey=True, figsize=(20,17))plt.subplots_adjust(left=None, bottom=None, right=None, top=None,wspace=None, hspace=0.)for i in range(n):map = Basemap(projection='merc', lat_0=0, lon_0=180,resolution='h', area_thresh=0.1,llcrnrlon=0, llcrnrlat=-45,urcrnrlon=360, urcrnrlat=45)map.drawcoastlines(linewidth=0.5)map.drawmapboundary()map.drawmapboundary()nx = data_all.shape[0]ny = data_all.shape[1]lon, lat = map.makegrid(ny[i], nx[i])z,y = map(lon, lat)cs = map.contourf(z, y, data_all[i])
Answer

I can't test it at the moment, but basically, you just need to tell basemap which axes to use.

For example:

import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemapfig, axes = plt.subplots(nrows=4, ncols=3)
for ax in axes.flat:map_ax = Basemap(ax=ax)map_ax.drawcoastlines()
plt.show()

enter image description here

https://en.xdnf.cn/q/70451.html

Related Q&A

Remove circular references in dicts, lists, tuples

I have this following really hack code which removes circular references from any kind of data structure built out of dict, tuple and list objects.import astdef remove_circular_refs(o):return ast.liter…

how to change image format when uploading image in django?

When a user uploads an image from the Django admin panel, I want to change the image format to .webp. I have overridden the save method of the model. Webp file is generated in the media/banner folder b…

Write info about nodes to a CSV file on the controller (the local)

I have written an Ansible playbook that returns some information from various sources. One of the variables I am saving during a task is the number of records in a certain MySQL database table. I can p…

Python minimize function: passing additional arguments to constraint dictionary

I dont know how to pass additional arguments through the minimize function to the constraint dictionary. I can successfully pass additional arguments to the objective function.Documentation on minimiz…

PyQt5 triggering a paintEvent() with keyPressEvent()

I am trying to learn PyQt vector painting. Currently I am stuck in trying to pass information to paintEvent() method which I guess, should call other methods:I am trying to paint different numbers to a…

A python regex that matches the regional indicator character class

I am using python 2.7.10 on a Mac. Flags in emoji are indicated by a pair of Regional Indicator Symbols. I would like to write a python regex to insert spaces between a string of emoji flags.For exampl…

Importing modules from a sibling directory for use with py.test

I am having problems importing anything into my testing files that I intend to run with py.test.I have a project structure as follows:/ProjectName | |-- /Title | |-- file1.py | |-- file2.py | …

Uploading and processing a csv file in django using ModelForm

I am trying to upload and fetch the data from csv file uploaded by user. I am using the following code. This is my html form (upload_csv1.html):<form action="{% url myapp:upload_csv %}" me…

Plotting Multiple Lines in iPython/pandas Produces Multiple Plots

I am trying to get my head around matplotlibs state machine model, but I am running into an error when trying to plot multiple lines on a single plot. From what I understand, the following code should…

libclang: add compiler system include path (Python in Windows)

Following this question and Andrews suggestions, I am trying to have liblang add the compiler system include paths (in Windows) in order for my Python codeimport clang.cindexdef parse_decl(node):refere…