5
$\begingroup$

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

$\endgroup$
3
  • $\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$ Jun 6, 2019 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$ Jun 6, 2019 at 18:58
  • $\begingroup$ Ok I will answer in regards to this use case then. $\endgroup$ Jun 6, 2019 at 19:30

2 Answers 2

7
$\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$
2
  • $\begingroup$ What's the supported file types for the file option ? $\endgroup$ Jun 6, 2019 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$ Jun 6, 2019 at 20:26
1
$\begingroup$

You should add interactive argument, if you want to see the figure, example:

qubit.draw(output='mpl', fold=50, interactive= True)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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