已解决 - 请参阅以下关于组合wraptext.wrap和评论的评论plt.tightlayout.
问题:这是代码:
import matplotlib.pyplot as plt
plt.bar([1,2],[5,4])
plt.title('this is a very long title and therefore it gets cropped which is an unthinkable behaviour as it loses the information in the title')
plt.show()
Run Code Online (Sandbox Code Playgroud)
这创造了一个看起来像的人物 
标题被裁剪,如何让它显示整个标题?
更新:我正在寻找一种解决方案,使图形大小与标题和轴标签中的文本相匹配,而不是用于使用换行符切割标题的解决方案,因为这种解决方案并不总是有用:
from textwrap import wrap
import matplotlib.pyplot as plt
title = 'this is a very long title and therefore it gets cropped which is an unthinkable behaviour as it loses the information in the title'*5
plt.bar([1,2],[5,4])
plt.title('\n'.join(wrap(title,60)))
plt.show()`
Run Code Online (Sandbox Code Playgroud)
看结果: 
我在Matlab写一个模拟.我最终将运行这个模拟数百次.在每次模拟运行中,都有数百万个模拟周期.在每个循环中,我计算一个非常复杂的函数,需要~0.5秒才能完成.函数输入是一个长位数组(> 1000位) - 这是一个0和的数组1.我认为该位阵列中的一个矩阵0和1,并为他们中的每一个我仅运行该函数一旦-正如我保存的结果在不同的阵列(RES),并检查比特阵列是在基体中运行的功能的前:
for i=1:1000000000
%pick a bit array somehow
[~,indx] = ismember(bit_array,bit_matrix,'rows');
if indx == 0
indx = length(results) + 1;
bit_matrix(indx,:) = bit_array;
res(indx) = complex_function(bit_array);
end
result = res(indx)
%do something with result
end
Run Code Online (Sandbox Code Playgroud)
我有两个问题,真的:
有没有更有效的方法来找到矩阵中的行的索引然后'ismember'?
由于我多次运行模拟,并且我得到的位数有很大的重叠,我想在运行之间缓存矩阵,这样我就不会在相同的位数组上重复计算函数再次.我怎么做?