cdelker / schemdraw

MIT License
103 stars 20 forks source link

Too large whitespace #1

Closed pozitron57 closed 1 year ago

pozitron57 commented 1 year ago

How can I control and trim the whitespace? matplotlib has bbox_inches='tight', is there something similar that can be used with schemdraw? The following code gives too much of blank space to the left of the actual figure. I tried svg backend, different formats, but it is always the same.

import schemdraw
import schemdraw.elements as elm

with schemdraw.Drawing() as d:
    E = d.add(elm.BatteryCell().up().label('$\mathcal{E}$'))
    d += elm.Capacitor(polar=True).right().label('$C$').reverse()
    d += elm.Inductor2().down().label('$L$',loc='bot')
    d += elm.Switch(action='close').left().label('$K$')

d.save('file.svg')
cdelker commented 1 year ago

I think it's leaving enough horizontal space to display the string "\mathcal{E}" rather than "ℰ". I'll see what I can do with it, but one workaround for this particular circuit is to skip the Latex math and just use the unicode symbol:

E = d.add(elm.BatteryCell().up().label('ℰ'))

pozitron57 commented 1 year ago

I see. Thanks for the idea. I did the following to keep the latex math:

from matplotlib import rc
rc('text', usetex=True)
rc('text.latex', preamble=r'\def\E{$\mathcal{E}$}')

...

    E = d.add(elm.BatteryCell().up().label('\E'))
cdelker commented 1 year ago

dfc2850