Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使matplotlib basemap轴的长度与另一个子地块轴相等?_Python_Matplotlib Basemap - Fatal编程技术网

Python 如何使matplotlib basemap轴的长度与另一个子地块轴相等?

Python 如何使matplotlib basemap轴的长度与另一个子地块轴相等?,python,matplotlib-basemap,Python,Matplotlib Basemap,在此问题上的任何帮助都将不胜感激。我在使用Basemap时遇到子地块问题。使用gridspec,我在matplotlib中创建了一个包含三个子地块的图形。我想画出底图的经纬度轴长度和其他2个子地块的轴相同。但在我当前的代码中,虽然两个子地块的纬度轴的长度相同,但经度轴的长度不同。如何平衡底图和左下象限子地块的经度轴长度?有没有办法做到这一点 这是我的密码: import pandas as pd import matplotlib.pyplot as plt from matplotlib.gr

在此问题上的任何帮助都将不胜感激。我在使用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)

使用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)

感谢您的快速回答@Dubbdan。为什么我要对figsize使用这样的特殊值?我认为你提到的设置与像素尺寸有关?地图高过宽。使用方形图
figsize=(12,12)
在两侧留有空格。我通过在QT窗口中调整绘图的大小得出了这些尺寸,并使用
fig.get\u size\u inches()。在我检查过之后,一切看起来都正常,我设置了
figsize
,以使绘图重现。尤其是在绘制GIS数据时,您永远不会真正知道合适的地物大小
figsize
用于以英寸为单位指定绘图的宽度和高度。它与像素尺寸有关,但并不完全相同。感谢您提供的信息性答案,它对我非常有帮助。那么请回答我的问题。感谢您的快速回答@Dubbdan。为什么我要对figsize使用这样的特殊值?我认为你提到的设置与像素尺寸有关?地图高过宽。使用方形图
figsize=(12,12)
在两侧留有空格。我通过在QT窗口中调整绘图的大小得出了这些尺寸,并使用
fig.get\u size\u inches()。在我检查过之后,一切看起来都正常,我设置了
figsize
,以使绘图重现。尤其是在绘制GIS数据时,您永远不会真正知道合适的地物大小
figsize
用于以英寸为单位指定绘图的宽度和高度。它与像素尺寸有关,但并不完全相同。感谢您提供的信息丰富的答案,它对我非常有帮助。那么请回答我的问题。