Repository: Qiskit/qiskit

Issue:
U3 gates expand too wide in MPL drawer
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues -->

### Information

- **Qiskit Terra version**: master
- **Python version**:
- **Operating system**:

### What is the current behavior?
<img width="435" alt="Screen Shot 2019-11-18 at 10 02 35 AM" src="https://user-images.githubusercontent.com/1249193/69063521-a5fc6400-09ea-11ea-84f6-fb14c023b9fe.png">



### Steps to reproduce the problem



### What is the expected behavior?



### Suggested solutions





Discussion:
I have tried to correct the irregularities in the width of wide gates like u2 and u3 in #3486 .
Hi @TharrmashasthaPV ! Does #3486 fixes this issue?
Hi @1ucian0 . Yes, the width of the gate boxes has been corrected so that it properly contains 'U3' and its parameters without having redundant extra spaces.
Great! I'm updating it. Thanks!

Resolving patch:
diff --git a/qiskit/visualization/matplotlib.py b/qiskit/visualization/matplotlib.py
--- a/qiskit/visualization/matplotlib.py
+++ b/qiskit/visualization/matplotlib.py
@@ -250,11 +250,18 @@ def _gate(self, xy, fc=None, wide=False, text=None, subtext=None):
 
         if wide:
             if subtext:
-                boxes_wide = round(max(len(subtext), len(text)) / 10, 1) or 1
+                subtext_len = len(subtext)
+                if '$\\pi$' in subtext:
+                    pi_count = subtext.count('pi')
+                    subtext_len = subtext_len - (4 * pi_count)
+
+                boxes_wide = round(max(subtext_len, len(text)) / 10, 1) or 1
                 wid = WID * 1.5 * boxes_wide
             else:
                 boxes_wide = round(len(text) / 10) or 1
                 wid = WID * 2.2 * boxes_wide
+            if wid < WID:
+                wid = WID
         else:
             wid = WID
         if fc:
@@ -664,25 +671,26 @@ def _draw_ops(self, verbose=False):
             for op in layer:
 
                 if op.name in _wide_gate:
+                    if layer_width < 2:
+                        layer_width = 2
                     if op.type == 'op' and hasattr(op.op, 'params'):
                         param = self.param_parse(op.op.params)
                         if '$\\pi$' in param:
                             pi_count = param.count('pi')
-                            len_param = len(param) - (5 * pi_count)
+                            len_param = len(param) - (4 * pi_count)
                         else:
                             len_param = len(param)
                         if len_param > len(op.name):
-                            box_width = round(len(param) / 10)
+                            box_width = math.floor(len(param) / 10)
                             # If more than 4 characters min width is 2
                             if box_width <= 1:
                                 box_width = 2
                             if layer_width < box_width:
                                 if box_width > 2:
-                                    layer_width = box_width * 2
+                                    layer_width = box_width
                                 else:
                                     layer_width = 2
-                    if layer_width < 2:
-                        layer_width = 2
+                            continue
 
                 # if custom gate with a longer than standard name determine
                 # width
@@ -696,11 +704,11 @@ def _draw_ops(self, verbose=False):
                         param = self.param_parse(op.op.params)
                         if '$\\pi$' in param:
                             pi_count = param.count('pi')
-                            len_param = len(param) - (5 * pi_count)
+                            len_param = len(param) - (4 * pi_count)
                         else:
                             len_param = len(param)
                         if len_param > len(op.name):
-                            box_width = round(len(param) / 8)
+                            box_width = math.floor(len(param) / 8)
                             # If more than 4 characters min width is 2
                             if box_width <= 1:
                                 box_width = 2


Test patch: