相关疑难解决方法(0)

使用matplotlib中的许多子图改进子图大小/间距

这个问题非常相似,但不同之处在于我的身材可以达到需要的大小.

我需要在matplotlib中生成一堆垂直堆叠的图.结果将使用figsave保存并在网页上查看,因此我不关心最终图像的高度,只要子图间隔开,这样它们就不会重叠.

无论我有多大的数字,子图总是似乎重叠.

我的代码目前看起来像

import matplotlib.pyplot as plt
import my_other_module

titles, x_lists, y_lists = my_other_module.get_data()

fig = plt.figure(figsize=(10,60))
for i, y_list in enumerate(y_lists):
    plt.subplot(len(titles), 1, i)
    plt.xlabel("Some X label")
    plt.ylabel("Some Y label")
    plt.title(titles[i])
    plt.plot(x_lists[i],y_list)
fig.savefig('out.png', dpi=100)
Run Code Online (Sandbox Code Playgroud)

python matplotlib

260
推荐指数
8
解决办法
32万
查看次数

我如何适合长冠军?

有一个类似的问题 - 但我不能让那里提出的解决方案有效.

这是一个带有长标题的示例图:

#!/usr/bin/env python

import matplotlib
import matplotlib.pyplot
import textwrap

x = [1,2,3]
y = [4,5,6]

# initialization:
fig = matplotlib.pyplot.figure(figsize=(8.0, 5.0)) 

# lines:
fig.add_subplot(111).plot(x, y)

# title:
myTitle = "Some really really long long long title I really really need - and just can't - just can't - make it any - simply any - shorter - at all."

fig.add_subplot(111).set_title("\n".join(textwrap.wrap(myTitle, 80)))

# tight:
(matplotlib.pyplot).tight_layout()

# saving:
fig.savefig("fig.png")
Run Code Online (Sandbox Code Playgroud)

它给了一个

 AttributeError: 'module' object has no attribute 'tight_layout'
Run Code Online (Sandbox Code Playgroud)

如果我 …

matplotlib

22
推荐指数
3
解决办法
2万
查看次数

标签 统计

matplotlib ×2

python ×1