Skip to content

Commit

Permalink
Limit params displayed in mpl drawer (#6443)
Browse files Browse the repository at this point in the history
* Limit params displayed in mpl drawer

* lint

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored May 20, 2021
1 parent 8591a3b commit c795068
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
13 changes: 8 additions & 5 deletions qiskit/visualization/matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,13 +436,16 @@ def _get_text_width(self, text, fontsize, param=False):
sum_text *= self._subfont_factor
return sum_text

def _param_parse(self, v):
param_parts = [None] * len(v)
for i, e in enumerate(v):
def _param_parse(self, params):
param_parts = []
for i, param in enumerate(params):
if i > 16:
param_parts.append("...")
break
try:
param_parts[i] = pi_check(e, output="mpl", ndigits=3)
param_parts.append(pi_check(param, output="mpl", ndigits=3))
except TypeError:
param_parts[i] = str(e)
param_parts.append(str(param))
param_parts = ", ".join(param_parts).replace("-", "$-$")
return param_parts

Expand Down
Binary file added test/ipynb/mpl/references/wide_params.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions test/ipynb/mpl/test_circuit_matplotlib_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,14 @@ def test_6095(self):
filename="6095.png",
)

def test_overwide_gates(self):
"""Test gates don't exceed width of default fold"""
circuit = QuantumCircuit(5)
initial_state = np.zeros(2 ** 5)
initial_state[5] = 1
circuit.initialize(initial_state)
self.circuit_drawer(circuit, filename="wide_params.png")


if __name__ == "__main__":
unittest.main(verbosity=1)

0 comments on commit c795068

Please sign in to comment.