0

The code example below runs without error, but nothing is displayed to the screen.

Here's the code example that I'm trying to use...

import SchemDraw
import SchemDraw.elements as elm

d = SchemDraw.Drawing()
R1 = d.add(elm.Resistor(label='1K$\Omega$'))
d.labelI(R1, '1 mA', top=False)
d.add(elm.Capacitor(d='down', botlabel='0.1$\mu$F'))
d.add(elm.Line( d='Left'))
d.add(elm.Ground)
d.add(elm.SourceV( d='up', label='10V') )
d.save('schematic.svg')
d.draw()

I'm on a Windows 7 platform and I have Python 3.7 integrated into my command prompt. If I navigate to the directory where my schematic.py file is located and I add this into the console:

Python schematic.py

It runs fine and exits with 0 error, but nothing is drawn to the screen, Matplotlib isn't even invoked...

After searching through some documents, brief tutorials, or examples that are very limited, I've come to realize that the above example, as well as others, rely on Jupyter Notebook with Matplotlib inlined...


How am I able to draw this without using Jupyter Notebook and inlining Matplotlib directly?

I would like to run it as a basic Python script and I know I can import the Matplotlib module manually like this...

import Matplotlib.pyplot as plt

//... prev code
d.draw() // doesn't draw anything to the screen or to matplotlib's backend...
// plt.plot(...)? What goes here?
plt.show()

But I don't know how to use it to draw the results from SchemDraw's draw method...

Francis Cugler
  • 7,788
  • 2
  • 28
  • 59

1 Answers1

1

Losing the Matplotlib interactive window was a regression bug introduced in SchemDraw 0.7. It was fixed in 0.7.1, pushed to PyPi today. In this version, d.draw() opens the Matplotlib window if running as a script, or shows output in the cell if running in Jupyter inline mode.

phoenix
  • 7,988
  • 6
  • 39
  • 45
Collin
  • 146
  • 4
  • I'm kind of new to Python. I've been learning it for the past year or so. I normally work with the C/C++ languages. I know what modules and packages are and I'm starting to get used to them... There's a slight transitional stage of training one's mindset switching from one language to the other. The more I work with Python doing random projects trying out different things, the more I become familiar with the language. I figured SchemDraw would be a good package to use without relying on an integrated notebook that does it for you! Thanks for the feedback. I'll have to check out the update! – Francis Cugler Jun 28 '20 at 04:04
  • Awesome! So there must have been a bug! I can now run the script file using Window's command prompt! I tried using `Jupyter-Notebook` through `Anaconda Explorer` and it's a bit convoluted... Too much involved to set up an environment, make that environment active, having to make sure all of the necessary packages are installed within that environment just to make something run, setting up a server, etc... I'd just want to install the package, write my python file or script, and run it through the command prompt! – Francis Cugler Jun 28 '20 at 04:48