I am trying to develop a flask app that is using matplotlib.figure, apparently I can't use pyplot according to their own suggestions.
I was reading from this response and I was using ax.set_title("whatever", pad=20)
that is effectively changing the height of my titles, but makes no difference to the 4 main graphs (they stay in the same position), I used other suggested solutions like \n
, but it seems that is not working.
This is part of my code, and I am also attaching how it looks:
# figsize = width, height (inches)
fig = Figure(figsize = (6,10))
# subplot(filas, columnas, index)
ax1 = fig.add_subplot(4, 1, 1)
ax1.plot(tiempo, data[0])
ax1.set_title('Canal 1')
ax1.set_xlabel('tiempo (s)')
ax1.set_ylabel('g\'s')
ax2 = fig.add_subplot(4, 1, 2)
ax2.plot(tiempo, data[1])
ax2.set_title('Canal 2')
ax2.set_xlabel('tiempo (s)')
ax2.set_ylabel('g\'s')
ax3 = fig.add_subplot(4, 1, 3)
ax3.plot(tiempo, data[2])
ax3.set_title('Canal 3')
ax3.set_xlabel('tiempo (s)')
ax3.set_ylabel('g\'s')
ax4 = fig.add_subplot(4, 1, 4)
ax4.plot(tiempo, data[3])
ax4.set_title('Canal 4')
ax4.set_xlabel('tiempo (s)')
ax4.set_ylabel('g\'s')
# Saving figure to the buffer
buf = BytesIO()
fig.savefig(buf, format = 'png')
image = base64.b64encode(buf.getbuffer()).decode("utf8")
return jsonify({'status': True, 'image': image})
Looked in many different places, but most solutions are for pyplot. Does anybody knows how to do this?