---
title: dag_drawer (v2.4)
description: API reference for qiskit.visualization.dag_drawer in qiskit v2.4
source: https://eu-de.quantum.cloud.ibm.com/docs/en/api/qiskit/2.4/qiskit.visualization.dag_drawer
---

# qiskit.visualization.dag\_drawer

`qiskit.visualization.dag_drawer(dag, scale=0.7, filename=None, style='color')`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.4/qiskit/visualization/dag_visualization.py#L76-L393)

Plot the directed acyclic graph (dag) to represent operation dependencies in a quantum circuit.

This function calls the [`graphviz_draw()`](https://www.rustworkx.org/apiref/rustworkx.visualization.graphviz_draw.html#rustworkx.visualization.graphviz_draw) function from the `rustworkx` package to draw the DAG.

> **Warning**
>
> This function will call the system Graphviz tool on a file involving user-controllable strings (such as operation labels). It is recommended to only call this function on trusted input.

**Parameters**

- **dag** ([*DAGCircuit*](/docs/api/qiskit/2.4/qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.DAGCircuit")  *or*[*DAGDependency*](/docs/api/qiskit/2.4/qiskit.dagcircuit.DAGDependency "qiskit.dagcircuit.DAGDependency")) – The dag to draw.

- **scale** ([*float*](https://docs.python.org/3/library/functions.html#float)) – scaling factor

- **filename** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) – file path to save image to (format inferred from name)

- **style** ([*dict*](https://docs.python.org/3/library/stdtypes.html#dict)  *or*[*str*](https://docs.python.org/3/library/stdtypes.html#str)) –

  Style name, file name of style JSON file, or a dictionary specifying the style.

  - **The supported style names are ‘plain’: B\&W graph, ‘color’ (default):**

    (color input/output/op nodes)

  - **If given a JSON file, e.g. `my_style.json` or `my_style` (the `.json`**

    extension may be omitted), this function attempts to load the style dictionary from that location. Note, that the JSON file must completely specify the visualization specifications. The file is searched for in `qiskit/visualization/circuit/styles`, the current working directory, and the location specified in `~/.qiskit/settings.conf`.

  - **If `None` the default style `"color"` is used or, if given, the default style**

    specified in `~/.qiskit/settings.conf`.

**Returns**

**if in Jupyter notebook and not saving to file,**

otherwise None.

**Return type**

PIL.Image

**Raises**

- [**VisualizationError**](/docs/api/qiskit/2.4/visualization#qiskit.visualization.VisualizationError "qiskit.visualization.VisualizationError") – when style is not recognized.
- [**InvalidFileError**](/docs/api/qiskit/2.4/exceptions#qiskit.exceptions.InvalidFileError "qiskit.exceptions.InvalidFileError") – when filename provided is not valid
- [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) – If the file extension for `filename` is not an image type supported by Graphviz.

**Example**

```python
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit.converters import circuit_to_dag
from qiskit.visualization import dag_drawer

q = QuantumRegister(3, 'q')
c = ClassicalRegister(3, 'c')
circ = QuantumCircuit(q, c)
circ.h(q[0])
circ.cx(q[0], q[1])
circ.measure(q[0], c[0])
with circ.if_test((c, 2)):
    circ.rz(0.5, q[1])

dag = circuit_to_dag(circ)

style = {
    "inputnodecolor": "pink",
    "outputnodecolor": "lightblue",
    "opnodecolor": "red",
}

dag_drawer(dag, style=style)
```
