So i have a matplotlib plot that is completely black with all axes disabled, the only thing present on the plot is white text, containing a mathematical expression, entered by the user, which is passed into the render function as the parameter 'expr'.
def render(expr, path, width, x, y):
fig = plt.figure(figsize=(width, 16 if 'begin' in expr else 12))
plt.text(x, y, expr, fontsize=320, fontweight='bold', color='white')
fig.set_facecolor('#000000')
plt.axis('off')
plt.savefig(path, facecolor=fig.get_facecolor())
plt.clf()
'width' is the width of the plot, currently i have an unintelligent system in place that strikes a relationship between the length of the plaintext expression and the width of the plot, but it does not work exactly especially with a matrix plot which has multiple lines, the system in place obviously doesn't work very well at all.
I want the required width of the plot to be calculated based on how much the white text stretches across the plot, so as soon as the text finishes widthwise, i want the plot to end there, is there a way of doing this?/ detecting when the white text would come to an end on the plot?
This is so that there is not a lot of black space after the expression, slowing down rendering time to .png and wasting space. As the plot is the same width as the expression