Repository: Qiskit/qiskit

Issue:
Incorrect shaded barriers in mpl drawer
Circuit with single qubit barriers on 2Q. The text drawn output is correct, but the mpl output is incorrect.

MPL (incorrect)

<img width="992" alt="image" src="https://user-images.githubusercontent.com/32201347/53523392-ae062380-3aaa-11e9-9c36-12f8ce2962bd.png">

Text (correct)

<img width="677" alt="image" src="https://user-images.githubusercontent.com/32201347/53523411-bfe7c680-3aaa-11e9-9716-d7cbebf71c97.png">

Qasm

'OPENQASM 2.0;\ninclude "qelib1.inc";\nqreg q7[3];\ncreg c7[2];\nu2(0.0,0.0) q7[0];\nbarrier q7[0];\nid q7[0];\nbarrier q7[0];\ny q7[0];\nbarrier q7[0];\nid q7[0];\nbarrier q7[0];\nid q7[0];\nbarrier q7[0];\nx q7[0];\nbarrier q7[0];\nid q7[0];\nbarrier q7[0];\nid q7[0];\nbarrier q7[0];\ny q7[0];\nbarrier q7[0];\nid q7[0];\nbarrier q7[0];\nid q7[0];\nbarrier q7[0];\nx q7[0];\nbarrier q7[0];\nid q7[0];\nbarrier q7[0];\nid q7[0];\nbarrier q7[0];\ny q7[0];\nbarrier q7[0];\nid q7[0];\nbarrier q7[0];\nu2(0.0,0.0) q7[0];\nu2(0.0,0.0) q7[2];\nbarrier q7[2];\nid q7[2];\nbarrier q7[2];\ny q7[2];\nbarrier q7[2];\nid q7[2];\nbarrier q7[2];\nid q7[2];\nbarrier q7[2];\nx q7[2];\nbarrier q7[2];\nid q7[2];\nbarrier q7[2];\nid q7[2];\nbarrier q7[2];\ny q7[2];\nbarrier q7[2];\nid q7[2];\nbarrier q7[2];\nid q7[2];\nbarrier q7[2];\nx q7[2];\nbarrier q7[2];\nid q7[2];\nbarrier q7[2];\nid q7[2];\nbarrier q7[2];\ny q7[2];\nbarrier q7[2];\nid q7[2];\nbarrier q7[2];\nu2(0.0,0.0) q7[2];\nbarrier q7[0],q7[1],q7[2];\nmeasure q7[0] -> c7[0];\nmeasure q7[2] -> c7[1];\n'



<!-- ⚠️ 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**: Latest pull from github
- **Python version**:  3.6
- **Operating system**: macox

### What is the current behavior?



### Steps to reproduce the problem



### What is the expected behavior?



### Suggested solutions





Discussion:
So I've been looking at this a bit more and I'm not actually convinced the `mpl` output is wrong, it's just not aligned/justified the same way as the `text` version. The part which is confusing here is the barrier style, the dark grey shading isn't actually the barrier, it's the dotted line. To verify that I came up with this little test:

```
import qiskit as qk
qr = qk.QuantumRegister(3)
qc = qk.QuantumCircuit(qr)
qc.h([qr[0], qr[1]])
qc.barrier([qr[0], qr[1]])
qc.h(qr[2])
qc.barrier(qr[2])
qc.y(qr)
qc.draw(output='mpl')
```

Which yielded:

![barrier-test](https://user-images.githubusercontent.com/2447371/53579011-c7f54400-3b46-11e9-93b1-6d59c2a9f520.png)

With that in mind when I ran that qasm through QuantumCircuit.draw() the circuit output was correct, it just didn't left justify everything. So the parts on q7[0] and q7[2] weren't lined up like in the text drawer. To make this a bit clearer I rendered the same qasm with the mpl backend and set the fold higher so it would put everything in a single row:

![mpl](https://user-images.githubusercontent.com/2447371/53579332-5d90d380-3b47-11e9-9975-c902404bd655.png)

It's not as nice looking as text, but there's nothing wrong with it. FWIW, the justify option is in progress here: https://github.com/Qiskit/qiskit-terra/pull/1797 
But, just out of curiosity I took a look look at the latex output from the same qasm generated circuit and that is really wrong on several fronts:

![latex](https://user-images.githubusercontent.com/2447371/53579824-4b636500-3b48-11e9-807f-2614683aef47.png)


So the latex issue is it doesn't apparently know how to draw iden gates (which is where those double barriers come from, the gap is where an iden gate should be). That'll be easy to fix and I'll push a patch in a second. The horizontal spacing on the barriers will be a bit trickier

Resolving patch:
diff --git a/qiskit/tools/visualization/_latex.py b/qiskit/tools/visualization/_latex.py
--- a/qiskit/tools/visualization/_latex.py
+++ b/qiskit/tools/visualization/_latex.py
@@ -225,7 +225,7 @@ def _get_image_depth(self, aliases=None):
             # useful information for determining row spacing
             boxed_gates = ['u0', 'u1', 'u2', 'u3', 'x', 'y', 'z', 'h', 's',
                            'sdg', 't', 'tdg', 'rx', 'ry', 'rz', 'ch', 'cy',
-                           'crz', 'cu3']
+                           'crz', 'cu3', 'id']
             target_gates = ['cx', 'ccx']
             if op['name'] in boxed_gates:
                 self.has_box = True
@@ -546,6 +546,8 @@ def _build_latex_array(self, aliases=None):
                             self._latex[pos_1][columns] = "\\gate{Z}"
                         elif nm == "h":
                             self._latex[pos_1][columns] = "\\gate{H}"
+                        elif nm == "id":
+                            self._latex[pos_1][columns] = "\\gate{Id}"
                         elif nm == "s":
                             self._latex[pos_1][columns] = "\\gate{S}"
                         elif nm == "sdg":
@@ -606,6 +608,8 @@ def _build_latex_array(self, aliases=None):
                             self._latex[pos_1][columns] = "\\gate{Z}"
                         elif nm == "h":
                             self._latex[pos_1][columns] = "\\gate{H}"
+                        elif nm == "id":
+                            self._latex[pos_1][columns] = "\\gate{Id}"
                         elif nm == "s":
                             self._latex[pos_1][columns] = "\\gate{S}"
                         elif nm == "sdg":


Test patch: