EXA Fix labels overlap in Out-of-core classification of text documents example
@@ -333,6 +333,7 @@ def plot_accuracy(x, y, x_legend):
plt.grid(True)
plt.plot(x, y)
+
rcParams['legend.fontsize'] = 10
cls_names = list(sorted(cls_stats.keys()))
@@ -370,7 +371,7 @@ ax = plt.subplot(111)
rectangles = plt.bar(range(len(cls_names)), cls_runtime, width=0.5,
color=bar_colors)
-ax.set_xticks(np.linspace(0.25, len(cls_names) - 0.75, len(cls_names)))
+ax.set_xticks(np.linspace(0, len(cls_names) - 1, len(cls_names)))
ax.set_xticklabels(cls_names, fontsize=10)
ymax = max(cls_runtime) * 1.2
ax.set_ylim((0, ymax))
@@ -385,8 +386,11 @@ def autolabel(rectangles):
ax.text(rect.get_x() + rect.get_width() / 2.,
1.05 * height, '%.4f' % height,
ha='center', va='bottom')
+ plt.setp(plt.xticks()[1], rotation=30)
+
autolabel(rectangles)
+plt.tight_layout()
plt.show()
# Plot prediction times
@@ -404,7 +408,7 @@ ax = plt.subplot(111)
rectangles = plt.bar(range(len(cls_names)), cls_runtime, width=0.5,
color=bar_colors)
-ax.set_xticks(np.linspace(0.25, len(cls_names) - 0.75, len(cls_names)))
+ax.set_xticks(np.linspace(0, len(cls_names) - 1, len(cls_names)))
ax.set_xticklabels(cls_names, fontsize=8)
plt.setp(plt.xticks()[1], rotation=30)
ymax = max(cls_runtime) * 1.2
@@ -412,4 +416,5 @@ ax.set_ylim((0, ymax))
ax.set_ylabel('runtime (s)')
ax.set_title('Prediction Times (%d instances)' % n_test_documents)
autolabel(rectangles)
+plt.tight_layout()
plt.show()
