4
$\begingroup$

Where does Qiskit put the rendered figure created by circuit.draw(output='mpl')?

$\endgroup$
  • $\begingroup$ Are you asking this question because when you run a program with circuit.draw(output='mpl'), the rendered Figure does not show up? Does it look like a new window appears and then instantly closes? Also, are you running this in Jupyter Notebooks or locally in the terminal? I have an answer for both just want to make sure I don't post an answer that doesn't apply to the method you are using. $\endgroup$ – Matthew Stypulkoski Jun 6 at 18:43
  • $\begingroup$ Yes nothing shows up, in the meantimei don't think i have installed anything related to that. i run code from the terminal $\endgroup$ – user1319236 Jun 6 at 18:58
  • $\begingroup$ Ok I will answer in regards to this use case then. $\endgroup$ – Matthew Stypulkoski Jun 6 at 19:30
6
$\begingroup$

Qiskit does not save the rendered Figure of the circuit anywhere, unless you provide a filename to the call.

For example: circuit.draw(filename='<file_path>').

In regards to having the Figure render and stay open, you simply need to remove a line of code. If you go to where qiskit is installed in your environment, go into the file qiskit/visualization/matplotlib.py, and go to line 436 you will see the line plt.close(self.figure). Comment this line out, and run your program again. You should see the Figure in a new window.

$\endgroup$
  • $\begingroup$ What's the supported file types for the file option ? $\endgroup$ – user1319236 Jun 6 at 19:52
  • $\begingroup$ I'm not sure of all of the supported file types, but I know that .png, .pdf, and .svg should be supported considering matplotlib uses them as examples on their documentation page $\endgroup$ – Matthew Stypulkoski Jun 6 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.