Reputation: 1108
I am making a pretty simple pandas/pylab bar plot with the following code:
df2 = pd.DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd'])
df2.plot(kind='bar', table=True)
plt.savefig('E:/chart.png')
The problem is that in the saved file chart.png the table is trimmed and only the first lines are visible. Is there any way to include the table in the image without having to make a subplot and render the table on a separate plot?
Upvotes: 2
Views: 157
Reputation: 21552
You can try to add bbox_inches='tight'
:
plt.savefig('chart.png', bbox_inches='tight')
this should solve the issue.
Upvotes: 2
Reputation: 21873
tight_layout is your friend:
plt.tight_layout(rect=(0,0.1,1,1))
where rect is:
interpreted as a rectangle (left, bottom, right, top) in the normalized figure coordinate that the whole subplots area (including labels) will fit into. Default is (0, 0, 1, 1)
See my answer here (and the other one) if you want to tweak a bit more your table:
https://stackoverflow.com/a/33110283/3297428
Upvotes: 2