如何将matplotlib-basemap轴的长度与另一个子图轴相等?

古多克

对此问题的任何帮助将不胜感激。使用底图时,子图出现问题。使用gridspec,我在matplotlib中创建了一个包含三个子图的图形。我想将底图的纬度和经度轴长度与其他2个子图的轴绘制为相同。但是在我当前的代码中,虽然两个子图的纬度轴的长度相同,但经度轴的长度却不同。如何使底图和左下象限子图的经度轴长度相等?有没有办法做到这一点?

这是我的代码:

import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
from mpl_toolkits.basemap import Basemap

fig = plt.figure(figsize=(12,12))
gs = GridSpec(2, 2, width_ratios=[3, 1], height_ratios=[3, 1], hspace=0.1, wspace=0.1)
ax1 = fig.add_subplot(gs[0])

map1 = Basemap(projection = 'merc', resolution = 'l',
               lat_0 = 39.65, lon_0 = 27.5, area_thresh = 0.1,
               llcrnrlon = 24.75, llcrnrlat = 35.25, urcrnrlon = 31.0, urcrnrlat = 41.5, ax=ax1)
map1.fillcontinents(color = 'darkgrey', lake_color = 'lightskyblue')
map1.drawmapboundary(fill_color = 'lightskyblue')
map1.drawcoastlines(linewidth = 1.0, color = 'black')
map1.drawcountries(linewidth = 0.5, color = 'black')
ax2 = fig.add_subplot(gs[1])
ax2.set_ylim(35.25, 41.5)
ax3 = fig.add_subplot(gs[2])
ax3.set_xlim(24.75, 31)

for i, ax in enumerate(fig.axes):
        ax.tick_params(labelbottom=False, labelleft=False)
        ax.set_xlabel("")
        ax.set_ylabel("")

ax1.set_xlabel("Longitude (°)", labelpad=10)
ax1.set_ylabel("Latitude (°)", labelpad=10)
ax2.set_xlabel("Depth (km)", rotation=180, labelpad=10)
ax2.set_ylabel("Latitude (°)", labelpad=10)
ax3.set_xlabel("Longitude (°)", labelpad=10)
ax3.set_ylabel("Depth (km)", labelpad=10)
杜布伯丹

使用GridSpec和设置figsize=(12,12)会导致子图未正确对齐。

我发现使用figsize=(6.3,8.12)生成的图已对齐。

fig = plt.figure(figsize = (6.3, 8.12))
gs = GridSpec(2, 2, width_ratios=[3, 1], height_ratios=[3, 1], hspace=0.2, wspace=0.2)
ax1 = fig.add_subplot(gs[0])

map1 = Basemap(projection = 'merc', resolution = 'l',
               lat_0 = 39.65, lon_0 = 27.5, area_thresh = 0.1,
               llcrnrlon = 24.75, llcrnrlat = 35.25, urcrnrlon = 31.0, urcrnrlat = 41.5, ax=ax1)
map1.fillcontinents(color = 'darkgrey', lake_color = 'lightskyblue')
map1.drawmapboundary(fill_color = 'lightskyblue')
map1.drawcoastlines(linewidth = 1.0, color = 'black')
map1.drawcountries(linewidth = 0.5, color = 'black')
ax2 = fig.add_subplot(gs[1])
ax2.set_ylim(35.25, 41.5)
ax3 = fig.add_subplot(gs[2])
ax3.set_xlim(24.75, 31)

for i, ax in enumerate(fig.axes):
        ax.tick_params(labelbottom=False, labelleft=False)
        ax.set_xlabel("")
        ax.set_ylabel("")

ax1.set_xlabel("Longitude (°)", labelpad=10)
ax1.set_ylabel("Latitude (°)", labelpad=10)
ax2.set_xlabel("Depth (km)", rotation=180, labelpad=10)
ax2.set_ylabel("Latitude (°)", labelpad=10)
ax3.set_xlabel("Longitude (°)", labelpad=10)
ax3.set_ylabel("Depth (km)", labelpad=10)

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何将一个子图的图例复制到matplotlib中的另一个子图

Matplotlib共享y轴-一个子图未对齐

使用 matplotlib 显示多个 y 轴脊时减少一个子图的宽度

matplotlib,在另一个子图的顶部放置一个透明的子图

Matplotlib:如何绘制两个具有相同x / y轴但一个沿y轴从另一个开始的条形图

Matplotlib 子图:轴共享的相等轴

如何将一个子域重写为另一个子域?

如何将子组件路由到另一个子组件

如何将工作表变量传递给另一个子

如何将列表的每个值传递给另一个子进程?

matplotlib 将子图组合成一个没有轴和间隙的图

如何将变量从一个子传递到另一个?

将轴尺寸限制为另一个轴的尺寸

如何在一个matplotlib轴中集成子图?

如何将子进程的输出传递给另一个子进程的输入?

如何在条形图上添加XY线以创建带有另一个轴的多型图?

如何将另一个数据框列的值显示为轴标签?

Matplotlib:仅一个子图具有相等的长宽比

在另一个子图上绘制Networkx图后,轴消失

Matplotlib如何将x轴缩放2倍

一个角度轴如何变换向量以匹配另一个方向?

将点击事件从一个子组件传递到另一个子组件

VBA EXCEL:如何在另一个子例程中调用一个子例程?

如何知道另一个子组件中一个子组件的事件

如何从另一个子域发送一个子域的综合浏览量

XSLT 如果另一个子元素重复,如何附加一个子元素

如何将 matplotlib 轴方面设置为与 twinx() 和 twiny() 相等

如何在包含轴标签的子图的角上放置一个字母(而不是轴的角)

如何基于另一个zip的内容创建一个子zip?