Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.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中创建方形半对数图(等维轴)?_Python_Matplotlib_Plot - Fatal编程技术网

如何在Python中创建方形半对数图(等维轴)?

如何在Python中创建方形半对数图(等维轴)?,python,matplotlib,plot,Python,Matplotlib,Plot,我试图在半对数比例上创建方形图(等长轴),但我没有运气。有人能帮我吗。对于日志比例,我使用了以下函数: def set_aspect_ratio_log(plot, aspect_ratio): x_min, x_max = plot.get_xlim() y_min, y_max = plot.get_ylim() return plot.set_aspect(aspect_ratio * ((math.log10(x_max / x_min)) / (math.log

我试图在半对数比例上创建方形图(等长轴),但我没有运气。有人能帮我吗。对于日志比例,我使用了以下函数:

def set_aspect_ratio_log(plot, aspect_ratio):
    x_min, x_max = plot.get_xlim()
    y_min, y_max = plot.get_ylim()
    return plot.set_aspect(aspect_ratio * ((math.log10(x_max / x_min)) / (math.log10(y_max / y_min)))
但是我如何在matplotlib中为半对数图创建这个函数呢

更新

import matplotlib.pyplot as plt
x = [12.4, 18.2, 20.3, 22.9, 27.7, 35.5, 53.9]
y = [1, 500, 600, 700, 800, 900, 1000]
fig = plt.figure(figsize=(3, 3))
fig.clf()
plot = plt.subplot(111)
plot.plot(x, y, linestyle = ':', marker='^', label='label')
plt.xscale('log')
plot.set_ylabel('y')
plot.set_xlabel('x')
plot.legend(title = 'Legend', loc = 'center left', bbox_to_anchor = (1.025, 0.5))
fig.savefig('plot.pdf', bbox_inches='tight')
我通过以下代码获得的输出数字:


通过测量浅灰色区域的尺寸,我发现它们不相等。

因此,似乎您希望轴的物理长度相等。在这种情况下,为什么不直接设置figsize?乙二醇

import pylab
pylab.figure( figsize=(3,3) )

我应该注意到,似乎set_方面与半对数图无关。不太清楚它会做什么:set_aspect的目的是设置与数据量表相关的纵横比。例如,设置_纵横比(1)将使x轴上的1个单位与y轴上的1个单位大小相同。如果数据比例不一样,那么就不清楚长宽比是什么意思。

我试过了,但没有给出相等的轴物理长度。嗯。。。默认情况下,该绘图与matplotlib不同。您是否显著更改了设置或导入了seaborn?相比之下,我使用完全相同的命令安装matplotlib确实创建了方形打印(我将其提高到6,6,而不是3,3,以便更容易在屏幕上看到)。是的,这不是默认设置。我稍微修改了matplotlibrc文件,主要是颜色设置。我有机会进一步处理这个问题,我确信问题与您修改的设置有关。您从gca()获得什么输出。获取位置()?