Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/288.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 - Fatal编程技术网

Python 打印大小随勾号字符数的变化而变化

Python 打印大小随勾号字符数的变化而变化,python,matplotlib,Python,Matplotlib,每当我使用matplotlib打印时,框取决于字符数。因此,如果要使用不同的y轴记号字符对齐两个图形,框大小将发生变化 import matplotlib.pyplot as plt data_a = [1, 10, 100, 1000, 10000] data_b = [10, 10.1, 9.9, 10.05, 9.95] data_c = [0, -0.0005, 0.00025, 0.00045, -0.00015] fig1, ax1 = plt.subplots() ax1.se

每当我使用
matplotlib
打印时,框取决于字符数。因此,如果要使用不同的y轴记号字符对齐两个图形,框大小将发生变化

import matplotlib.pyplot as plt

data_a = [1, 10, 100, 1000, 10000]
data_b = [10, 10.1, 9.9, 10.05, 9.95]
data_c = [0, -0.0005, 0.00025, 0.00045, -0.00015]

fig1, ax1 = plt.subplots()
ax1.semilogx(data_a, data_b, 'bo')
ax1.set_xlabel('x-axis')
ax1.set_ylabel('y-axis')
ax1.set_title('fig1')
plt.show()

fig2, ax2 = plt.subplots()
ax2.semilogx(data_a, data_c, 'r*')
ax2.set_xlabel('x-axis')
ax2.set_ylabel('y-axis')
ax2.set_title('fig2')
plt.show()

fig1.savefig('test1.pdf', bbox_inches='tight')
fig2.savefig('test2.pdf', bbox_inches='tight')
输出给了我两个数字,这两个数字在盒子的大小上是不一样的。这是因为
fig1
的y轴刻度与
fig2
的刻度大小不同。区别不大,但每当我在文档中添加它并对齐它们时,它都是可见的,因此很烦人

  • 有没有办法确保纵横比(或者说y轴和x轴)与小数位数无关,从而使长方体保持相同的大小

我试着玩弄纵横比,也使用了相同的
figsize
,但没有任何运气。

删除
bbox\u inches='tight'
,因为这样会裁剪图形,而且您似乎希望避免这种情况。谢谢,@ImportanceOfBeingErnest。如果我这样做,就会出现其他问题(但本例中可能没有)。这里发生的唯一一件事是,移除
bbox\u inches='tight'
会部分移除
code
。它还可以剪切其他东西(此处未显示),如
图例
。它将“删除”图形边界之外的所有内容。从这个意义上说,“删除”可能是错误的观点——它宁愿“不包括”这些。只要确保您需要显示的所有内容都在图中即可。