Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix barrier label when output='mpl' #13971

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions qiskit/visualization/circuit/matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1360,10 +1360,11 @@ def _measure(self, node, node_data, outer_circuit, glob_data):

def _barrier(self, node, node_data, glob_data):
"""Draw a barrier"""
topmost_node = len(node_data[node].q_xy) - 1 if self._reverse_bits else 0
for i, xy in enumerate(node_data[node].q_xy):
xpos, ypos = xy
# For the topmost barrier, reduce the rectangle if there's a label to allow for the text.
if i == 0 and node.op.label is not None:
if i == topmost_node and node.op.label is not None:
ypos_adj = -0.35
else:
ypos_adj = 0.0
Expand All @@ -1388,7 +1389,7 @@ def _barrier(self, node, node_data, glob_data):
self._ax.add_patch(box)

# display the barrier label at the top if there is one
if i == 0 and node.op.label is not None:
if i == topmost_node and node.op.label is not None:
dir_ypos = ypos + 0.65 * HIG
self._ax.text(
xpos,
Expand Down Expand Up @@ -1970,7 +1971,6 @@ def _line(self, xy0, xy1, lc=None, ls=None, zorder=PORDER_LINE):

def _plot_coord(self, x_index, y_index, gate_width, glob_data, flow_op=False):
"""Get the coord positions for an index"""

# Check folding
fold = self._fold if self._fold > 0 else INFINITE_FOLD
h_pos = x_index % fold + 1
Expand Down