I want a plot with two subplots, one larger with a map and second smaller with a scatter plot. I am using cartopy for plotting map. I determine the fraction of height by using gridspec_kw. However, due to projection constraints, it also affects the width..
这就是我得到的。
import matplotlib.pyplot as plt
import cartopy as ccrs
fig, ax = plt.subplots(2,1,subplot_kw=dict(projection=ccrs.crs.PlateCarree()),gridspec_kw={'height_ratios': [4, 1]})
一种可能的解决方案是仅对上面板使用 subplot_kw=dict(projection=ccrs.crs.PlateCarree() 。但我无法弄清楚如何做到这一点。有一些方法推荐 add_subplot ,但这是非常手动的我不喜欢这个。可以用 plt.subplots() 来做吗?
This is what I want.
我的建议是使用gridspec
控制子图的大小和fig.add_subplot
代替plt.subplots
。这样您就可以仅将 Cartopy 投影指定到第一个子图。
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import cartopy.crs as ccrs
import cartopy.feature as cfeature
fig = plt.figure()
gs = fig.add_gridspec(3, 3)
ax1 = fig.add_subplot(gs[0:2, :], projection=ccrs.PlateCarree())
ax1.set_extent([-180, 180, -90, 90], crs=ccrs.PlateCarree())
ax1.coastlines(resolution='auto', color='k')
ax1.gridlines(color='lightgrey', linestyle='-', draw_labels=True)
ax2 = fig.add_subplot(gs[2, :])
ax2.plot([1, 2], [3, 4])
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)