Skip to content

Commit

Permalink
refactor: use style argument to update dpi
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoRobbiati committed Oct 28, 2024
1 parent b062751 commit 3b2d675
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
8 changes: 4 additions & 4 deletions examples/circuit-draw-mpl/qibo-draw-circuit-matplotlib.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 17,
"id": "626f9d58",
"metadata": {},
"outputs": [
Expand All @@ -471,12 +471,12 @@
"c.add(gates.M(0,1))\n",
"\n",
"# small dpi value\n",
"plot_circuit(c.fuse(), scale = 0.8, cluster_gates = True, dpi=80);"
"plot_circuit(c.fuse(), scale = 0.8, cluster_gates = True, style={\"dpi\": 80});"
]
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 18,
"id": "539ef4b7-76fe-4d72-b3f4-78baf44d526d",
"metadata": {},
"outputs": [
Expand All @@ -493,7 +493,7 @@
],
"source": [
"# higher definition\n",
"plot_circuit(c.fuse(), scale = 0.8, cluster_gates = True, dpi=1000);"
"plot_circuit(c.fuse(), scale = 0.8, cluster_gates = True, style={\"dpi\": 1000});"
]
},
{
Expand Down
7 changes: 2 additions & 5 deletions src/qibo/ui/mpldrawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,11 @@ def _swapx(ax, x, y, plot_params):

def _setup_figure(nq, ng, gate_grid, wire_grid, plot_params):
scale = plot_params["scale"]
matplotlib.pyplot.rcParams["figure.dpi"] = plot_params["dpi"]
matplotlib.pyplot.rcParams["savefig.dpi"] = plot_params["dpi"]
fig = matplotlib.pyplot.figure(
figsize=(ng * scale, nq * scale),
facecolor=plot_params["facecolor"],
edgecolor=plot_params["edgecolor"],
dpi=plot_params["dpi"],
)
ax = fig.add_subplot(1, 1, 1, frameon=True)
ax.set_axis_off()
Expand Down Expand Up @@ -632,7 +631,7 @@ def _plot_params(style: Union[dict, str, None]) -> dict:
return style


def plot_circuit(circuit, scale=0.6, cluster_gates=True, style=None, dpi=100):
def plot_circuit(circuit, scale=0.6, cluster_gates=True, style=None):
"""Main matplotlib plot function for Qibo circuit
Args:
Expand All @@ -641,7 +640,6 @@ def plot_circuit(circuit, scale=0.6, cluster_gates=True, style=None, dpi=100):
cluster_gates (boolean): Group (or not) circuit gates on drawing.
style (Union[dict, str, None]): Style applied to the circuit, it can a built-in sytle or custom
(built-in styles: garnacha, fardelejo, quantumspain, color-blind, cachirulo or custom dictionary).
dpi: plot resolution, expressed in terms of dots per inches (DPI).
Returns:
matplotlib.axes.Axes: Axes object that encapsulates all the elements of an individual plot in a figure.
Expand Down Expand Up @@ -689,7 +687,6 @@ def plot_circuit(circuit, scale=0.6, cluster_gates=True, style=None, dpi=100):

params = PLOT_PARAMS.copy()
params.update(_plot_params(style))
params["dpi"] = dpi

inits = list(range(circuit.nqubits))

Expand Down

0 comments on commit 3b2d675

Please sign in to comment.