散点图标记大小与轴值成正比 - 为什么对于方面=“等于”,x 轴和 y 轴的像素数不同?

lem*_*dan 5 python size matplotlib markers scatter-plot

据我所知,我的问题与这篇文章密切相关。

我需要绘制一些标记大小与轴值严格成比例的数据。(已经在这里问过这个问题)。

我的方法如下:

  • 创建空散点图作为像素参考
  • 在左下角和右上角散布2个点
  • 将轴限制在这两点上
  • 用于transData.transform获取这两个点的像素值
  • 获取像素距离作为这两点的像素数差
  • (现在我有了距离与像素之比,用 ; 分散我的数据
    s=(size*dist_to_pix_ratio)**2,但这现在并不重要。)

问题是:当我完全按照我所描述的操作时,我得到 y 轴和 x 轴像素数的两个不同值。

这是一个最小的代码:

import matplotlib.pyplot as plt

fig = plt.figure(figsize=(7,7))
ax1 = fig.add_subplot(111, aspect='equal')

#setting up an empty scatterplot for pixel reference
xedges=[0.0, 1.0]
yedges=[0.0, 1.0]
emptyscatter=ax1.scatter(xedges, yedges, s=0.0)

#set axes limits
ax1.set_xlim(0.00,1.00)
ax1.set_ylim(0.00,1.00)   


# Calculating the ratio of pixel-to-unit
upright = ax1.transData.transform((1.0,1.0))
lowleft = ax1.transData.transform((0.0,0.0))
x_to_pix_ratio = upright[0] - lowleft[0]
y_to_pix_ratio = upright[1] - lowleft[1]

print x_to_pix_ratio, y_to_pix_ratio
Run Code Online (Sandbox Code Playgroud)

返回:

434.0 448.0
Run Code Online (Sandbox Code Playgroud)

谁能解释一下为什么他们不相等?

我不确定它是否相关,但我正在使用 Python 2.7.12 和 matplotlib 1.5.1