Note that there are some explanatory texts on larger screens.

plurals
  1. POMathTextParser: Fit output to figsize
    primarykey
    data
    text
    <p>I am using <code>MathTextParser</code> to depict some equations in Qt. Therefore i get the required tex string out of a dict, parse it using the to_rgba method of the parser i created (handing over a general fontsize and dpi) and finally hand this to my <code>FigureCanvas</code> of the <code>QWidget</code> by <code>figimage</code>.<br> Have a look: </p> <pre><code>class MathWidget(QWidget): def __init__(self, parent = None): QWidget.__init__(self, parent) ... self.canvas = MathCanvas() # The FigureCanvas to display the teximage ... self.parser = mathtext.MathTextParser("Bitmap") def render(self,metric): equation = self.equations[metric] rgb, d = self.parser.to_rgba(equation, color='black', fontsize=8, dpi=200) self.canvas.fig.figimage(rgb.astype(float)/255., 0, 0) self.canvas.draw() </code></pre> <p>My problem now is, that the equations to be parsed are of varying length whereas the <code>FigureCanvas</code> has a fixed size (as it needs to have) so that it happens, that some equations result in an image, which exceeds the figure in its size so that some part of the equation is cut off/not visible, like in this example:<br> <a href="http://wwwpub.zih.tu-dresden.de/~s4901563/exceed.png" rel="nofollow">Cut off equation</a><br> What i wouldn't like to do is to somehow predefine a fontsize for every tex string depeding on its length, for the reason that even user defined equations (of unpredictable length) need to be parsed and displayed.<br> So is there by any chance a way to make the parser fit the e.g. fontsize, so that the output is a rasterized tex of a fixed size independently of the equation size/length? </p> <p>Besides: In comparison to e.g. numpy/scipy the docs of matplotlib seem inscrutable to me for some reason, thus if somebody could comment on how <code>to_rgba</code> and <code>figimage</code> exactly work i'd be grateful, too.. e.g. concerning to_rgba: what means the following quote elucidating depth?: </p> <blockquote> <ul> <li>depth is the offset of the baseline from the bottom of the image in pixels</li> </ul> </blockquote> <p>Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload