3
$\begingroup$

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.

EDIT:

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.

$\endgroup$
3
$\begingroup$

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)

$\endgroup$
3
  • $\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$ – user2820579 May 20 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 May 20 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$ – user2820579 May 20 at 13:05

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.