Reusing Axes in context-manager Drawing
Issue #73
resolved
Hi, I've been trying to use schemdraw with existing matplotlib figure and axes (e.g. for inset schematics or for grid layouts). As far as I can tell, the intended way is to do it like this:
d = schemdraw.Drawing()
d += elm.SourceControlledI().up()
d += elm.Line().right()
d += elm.Resistor().down().label('50', loc='bottom')
d += elm.Line().left()
d.draw(ax=plt.subplot(121))
plt.subplot(122)
plt.show()
Apart from the axes showing on the left plot and the '50' label being clipped, this produces the intended result.
This syntax doesn't allow to use the context manager syntax though, since Drawing doesn't react to an ax keyword, and even if it would, the schematics would be displayed separate from the main output on exit.
Would it be acceptable to allow it to also accept ax in the Drawing constructor? Ideally, also skipping displaying in __exit__
if on user figure. I can create a pull request.
Comments (2)
-
repo owner -
repo owner - changed status to resolved
- Log in to comment
Yes, that would be ideal behavior. I’d be happy to take a pull request for it.