currently I am trying to save a matplotlib plot as a PDF, however the Y axis is not being shown in the final figure despite being displayed in the plot. More specifically, I have the following subplots:
import matplotlib.pyplot as plt
from numpy import random
sizes=22
x1 = random.randint(2000, size=(125))
x2 = random.randint(1000, size=(125))
plt.subplot(2, 3, 1)
plt.plot(x1, color='red')
plt.plot(x2, color='blue')
plt.yticks(fontsize=sizes)
plt.xticks(fontsize=sizes)
plt.title("Plot 1", fontsize=sizes)
plt.gcf().text(-0.02,0.45, "Y-axis", ha="center", va="center", rotation=90, fontsize=sizes)
x1 = random.randint(2000, size=(125))
x2 = random.randint(1000, size=(125))
plt.subplot(2, 3, 2)
plt.plot(x1, label="Sobriedade", color='red')
plt.plot(x2, label="Ebriedade", color='blue')
plt.yticks(fontsize=sizes)
plt.xticks(fontsize=sizes)
leg = pp.legend(loc='lower center',fontsize=sizes, bbox_to_anchor=[0.5, 1.25], ncol=2)
plt.title("Plot 2", fontsize=sizes)
x1 = random.randint(2000, size=(125))
x2 = random.randint(1000, size=(125))
plt.subplot(2, 3, 3)
plt.plot(x1, color='red')
plt.plot(x2, color='blue')
plt.yticks(fontsize=sizes)
plt.xticks(fontsize=sizes)
plt.title("Plot 3", fontsize=sizes)
x1 = random.randint(2000, size=(125))
x2 = random.randint(1000, size=(125))
plt.subplot(2, 3, 4)
plt.plot(x1, color='red')
plt.plot(x2, color='blue')
plt.yticks(fontsize=sizes)
plt.xticks(fontsize=sizes)
plt.title("Plot 4", fontsize=sizes)
x1 = random.randint(2000, size=(125))
x2 = random.randint(1000, size=(125))
plt.subplot(2, 3, 5)
plt.plot(x1, color='red')
plt.plot(x2, color='blue')
plt.yticks(fontsize=sizes)
plt.xticks(fontsize=sizes)
plt.title("Plot 5", fontsize=sizes)
plt.xlabel('X-Axis', fontsize=sizes)
x1 = random.randint(2000, size=(125))
x2 = random.randint(1000, size=(125))
plt.subplot(2, 3, 6)
plt.plot(x1, color='red')
plt.plot(x2, color='blue')
plt.yticks(fontsize=sizes)
plt.xticks(fontsize=sizes)
plt.title("Plot 6", fontsize=sizes)
plt.rcParams['figure.figsize'] = (18, 14)
plt.tight_layout()
plt.show()
In this line specifically:
plt.gcf().text(-0.02,0.45, "Y-axis", ha="center", va="center", rotation=90, fontsize=sizes)
It is an attempt to add a describing label to the left side of the overall plot. It works when plotting. However when I do plt.savefig()
The said side label is not there.
The above image is a result from the example above. Therefore, when i do plt.savefig() i was expecting the y-axis label to be also saved in the figure. However, it isn't saved. This is what happens actually:
I'd like to know how can I make sure that the label on y-axis is actually saved when i save the figure?
CodePudding user response: