Is there a way to save vectorized images in Qiskit? I am using

circuit.draw('latex', filename='./file.pdf')

They type of the image is a pdf, but it looks like a png exported as a pdf. For reference I attach here a figure of the differences I point out.

enter image description here

Hopefully some differences can be noticed. The top subfigure was made with Quantikz, while the other directly with Qiskit. The difference that the top is vectorized and the other looks like it isn't.


The problem is solved using what luciano pointed out. I just want to add that the resulting pdf circuit may still need some cleaning. Apparently the figure is not "tight framed", I attach an example of what I mean

enter image description here

The letters that appear at the bottom are part of the figure caption. One can see that there's a huge space between the image and the caption, along with a border that frames the image.

  • $\begingroup$ For Googlers, .svg output seems to work fine nowadays, useful for certain use cases. $\endgroup$ Commented Sep 19, 2023 at 17:23

1 Answer 1


With 'latex_source' you can save the LaTeX file and compile it later with pdflatex

In an interactive console (such a Jupyter notebook), you can run the following:

circuit.draw('latex_source', filename='./file.tex')
!pdflatex file.tex

This will create a file.pdf in actual PDF format.

(I understand this is very unintuitive, I submitted a fix to it)

  • $\begingroup$ Ah I see, thanks. The docs are a little bit confusing in this part. I will add some extra feature that I find, hopefully this can also be corrected in the upcoming patches. $\endgroup$ Commented May 20, 2021 at 9:22
  • $\begingroup$ if you need to insert the circuit image in another latex file, you can paste the relevant part of latex_source output in it. $\endgroup$
    – luciano
    Commented May 20, 2021 at 12:22
  • $\begingroup$ Ok, I just thought that something similar to bbox_inches='tight' could be made here (it could help when writting thesis or papers). $\endgroup$ Commented May 20, 2021 at 13:05

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.