Reputation: 64024
I have the following image:
Created with this code:
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
# create some random data
data = pd.DataFrame(np.random.rand(11, 5), columns=['A', 'B', 'C', 'D', 'E'], index = ['yyyyyyyy - ' + str(x) for x in range(2000, 2011, 1)])
# plot heatmap
ax = sns.heatmap(data.T)
# turn the axis label
for item in ax.get_yticklabels():
item.set_rotation(0)
for item in ax.get_xticklabels():
item.set_rotation(90)
# save figure
plt.savefig('seabornPandas.png', dpi=100)
plt.close()
My question is how can I adjust the image so that the truncated x-axis showed its full string?
Upvotes: 0
Views: 861
Reputation: 3893
There's a convenient way to do this through a subplots_adjust
method:
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
# create some random data
data = pd.DataFrame(np.random.rand(11, 5), columns=['A', 'B', 'C', 'D', 'E'], index = ['yyyyyyyy - ' + str(x) for x in range(2000, 2011, 1)])
# plot heatmap
plt.ion()
ax = sns.heatmap(data.T)
# adjust to taste
ax.figure.subplots_adjust(bottom = 0.25)
# turn the axis label
for item in ax.get_yticklabels():
item.set_rotation(0)
for item in ax.get_xticklabels():
item.set_rotation(90)
# save figure
plt.savefig('seabornPandas.png', dpi=100)
Upvotes: 2