matplotlib和地理数据图的纵横比 [英] matplotlib and apect ratio of geographical-data plots
问题描述
我处理地理信息并使用
matplotlib.所有输入均为纬度/经度[度].我转换成
x/y [米]用于我的计算.我将我的结果呈现在
纬度/经度.问题是要获得图形的长宽比
正确:所有图形都太宽.是否有标准程序来设置
正确的宽高比,因此我可以简单地绘制散点图和其他图表
使用纬度/经度,结果具有正确的形状?在屏幕上和
纸(png)?
I process geographical information and present the results using
matplotlib. All input is lattitude/longitude [degree]. I convert into
x/y [meter] for my calculations. And I present my results in
lattitude/longitude. The problem is to get the graphs aspect-ratio
right: All graphs are too wide. Is there a standard procedure to set the
correct aspect-ratio so I can simply draw my scatter and other diagrams
using lat/lon and the result has the correct shape? On screen and on
paper (png)?
[稍后添加此部分] 这是我的问题的裸露的版本.我需要实际的经/纬度值 围绕轴和准确的形状(正方形).现在,它看起来很宽(2倍).
[added this part later] This is a bare-bone stripped version of my problem. I need actual lat/lon values around the axes and an accurate shape (square). Right now it appears wide (2x).
import math
import matplotlib.pyplot as plt
import numpy as np
from pylab import *
w=1/math.cos(math.radians(60.0))
plt_area=[0,w,59.5,60.5] #60deg North, adjacent to the prime meridian
a=np.zeros(shape=(300,300))
matshow(a, extent=plt_area)
plt.grid(False)
plt.axis(plt_area)
fig = plt.gcf()
fig.set_size_inches(8,8)
fig.subplots_adjust(left=0.1, right=0.9, bottom=0.1, top=0.9)
plt.show()
推荐答案
似乎我找到了解决方案. 我在这里找到它:如何在matplotlib中设置长宽比? >
It seems I found the solution. And I found it here: How can I set the aspect ratio in matplotlib?
import math
import matplotlib.pyplot as plt
import numpy as np
w=1/math.cos(math.radians(60.0))
plt_area=[0,w,59.5,60.5] #square area
a=np.zeros(shape=(300,300))
fig = plt.figure()
ax = fig.add_subplot(111)
ax.imshow(a)
plt.grid(False)
ax.axis(plt_area)
fig = plt.gcf()
fig.set_size_inches(8,8)
ax.set_aspect(w)
fig.subplots_adjust(left=0.1, right=0.9, bottom=0.1, top=0.9)
plt.show()
这篇关于matplotlib和地理数据图的纵横比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!