Repository: Qiskit/qiskit

Issue:
drawing the schedule of an empty circuit raises warning from matplotlib
### Information

- **Qiskit Terra version**: master
- **Python version**: 3.8
- **Operating system**: MacOS

### What is the current behavior?

```
from qiskit import schedule, QuantumCircuit, transpile
from qiskit.test.mock import FakeOpenPulse2Q

circuit = QuantumCircuit(1)

schedule(circuit, FakeOpenPulse2Q()).draw()
```
```
.../qiskit-terra/qiskit/visualization/pulse_v2/plotters/matplotlib.py:160: UserWarning: Attempting to set identical left == right == 0.0 results in singular transformations; automatically expanding.
  self.ax.set_xlim(*axis_config.window)
.../qiskit-terra/venv/lib/python3.8/site-packages/matplotlib/tight_bbox.py:71: RuntimeWarning: divide by zero encountered in double_scalars
  fig.patch.set_bounds(x0 / w1, y0 / h1,
.../qiskit-terra/venv/lib/python3.8/site-packages/matplotlib/tight_bbox.py:72: RuntimeWarning: divide by zero encountered in double_scalars
  fig.bbox.width / w1, fig.bbox.height / h1)
.../qiskit-terra/venv/lib/python3.8/site-packages/matplotlib/patches.py:769: RuntimeWarning: invalid value encountered in double_scalars
  y1 = self.convert_yunits(self._y0 + self._height)
.../venv/lib/python3.8/site-packages/matplotlib/transforms.py:2013: RuntimeWarning: invalid value encountered in double_scalars
  self._mtx[1, 2] += ty
```

### What is the expected behavior?

I think the actual output drawing is correct. 
![image](https://user-images.githubusercontent.com/766693/112750161-23fd5180-8fc7-11eb-9cf3-474aef62f6e4.png)

However, I dont think these warnings are useful and they should be removed.

### Suggested solutions

I think giving some dummy values is probably the cleanest way to remove these obscure warnings. 




Discussion:
I am new to quantum computing and programming in general. I have learnt python. I am willing to solve this issue
 
Assigned! Thank you! 
@1ucian0  I was running the program in juypiter notebook but no such warning massages were displayed
![Screenshot from 2021-03-30 23-20-00](https://user-images.githubusercontent.com/72877136/113033399-9b410a00-91ae-11eb-9422-751937cd5d86.png)
![Screenshot from 2021-03-30 23-20-04](https://user-images.githubusercontent.com/72877136/113033405-9da36400-91ae-11eb-876d-f938bc03e83a.png)
![Screenshot from 2021-03-30 23-20-06](https://user-images.githubusercontent.com/72877136/113033420-a005be00-91ae-11eb-9be7-7137c2b55024.png)

@1ucian0  please tell me where the problem is arising?
Hmm... in master the out is different. Maybe a regression?

<img width="756" alt="Screenshot 2021-03-30 at 21 34 32" src="https://user-images.githubusercontent.com/766693/113046164-00d9ca00-91a0-11eb-822a-2bdaa5b6df91.png">

Indeed, it is a regression inserted in https://github.com/Qiskit/qiskit-terra/pull/5581

Maybe @nkanazawa1989 has any insights? 
@1ucian0  in my computer, in the master branch it is showing the modules of qiskit are not present even though the I am installes qiskit. Please have a look sir.
![Screenshot from 2021-03-31 19-52-43](https://user-images.githubusercontent.com/72877136/113160104-cb45e700-925a-11eb-9f5a-14ae82a8e144.png)

@Atri22 have you followed these [instructions](https://qiskit.org/documentation/contributing_to_qiskit.html#installing-terra-from-source) to install Qiskit terra from source? 
Visualization of zero duration schedule is not tested, so this is a corner case. Here the plotter sets the xaxis but with above input `axsis_config.window = (0., 0.)` crashes matplotlib.
https://github.com/Qiskit/qiskit-terra/blob/f016354f76a0b1b5c68ffc7210b41c4c15712ddd/qiskit/visualization/pulse_v2/plotters/matplotlib.py#L160

Above config object is generated by the formatter `time_map_in_ns` by default.
https://github.com/Qiskit/qiskit-terra/blob/f016354f76a0b1b5c68ffc7210b41c4c15712ddd/qiskit/visualization/pulse_v2/layouts.py#L308-L363

Such callback functions are stored in the stylesheet, so that user can modify almost all appearance of image without codebase modification.
https://github.com/Qiskit/qiskit-terra/blob/f016354f76a0b1b5c68ffc7210b41c4c15712ddd/qiskit/visualization/pulse_v2/stylesheet.py#L121

You need to set some minimum window length. Since v2 drawer can take arbitrary formatter function to generate such configuration, perhaps it's better to add zero duration check in the plotter rather than in the formatter. 
@nkanazawa1989 sir,can you please tell me where and how to add zero duration check and set minimum window length.
> @nkanazawa1989 sir,can you please tell me where and how to add zero duration check and set minimum window length.

@Atri22 you can find the plotter in `qiskit-terra/qiskit/visualization/pulse_v2/plotters/matplotlib.py`, on line 79 you can see where the `axis_config` is set. This could be a a good place to check for zero duration (i.e. if the `time_range` is 0.0,0.0) and set a minimum `time_window`. Unless @nkanazawa1989 suggests otherwise?
@1ucian0 sir recently when I try to run the program in my terminal certain issues pop up.Are they due to any recent changes in the program? How to handle them?
![Screenshot from 2021-04-30 16-59-24](https://user-images.githubusercontent.com/72877136/116691566-969f8980-a9d8-11eb-8b60-c7e89855b195.png)

hi. is the issue already fixed... otherwise I would love to work on that

> @1ucian0 sir recently when I try to run the program in my terminal certain issues pop up.Are they due to any recent changes in the program? How to handle them?
> ![Screenshot from 2021-04-30 16-59-24](https://user-images.githubusercontent.com/72877136/116691566-969f8980-a9d8-11eb-8b60-c7e89855b195.png)

Hi @Atri22 it's difficult to tell what the issue is from this screenshot, I would recommend double checking you've installed qiskit from source correctly (instructions [here](https://qiskit.org/documentation/contributing_to_qiskit.html#installing-terra-from-source)). It looks like you might have missed the `pip install -e .` step. Also make sure that you've pulled the latest version of main.
> hi. is the issue already fixed... otherwise I would love to work on that

Hi @MR-Asif12116135 this issue is already assigned to @Atri22, so feel free to take a look at some of the other issues that are tagged as 'good first issues', there are a few that are not assigned to anyone yet 😄 
Hi @Atri22, are you still working on the issue? Otherwise I'd like to work on a fix based on @1ucian0 suggestions. Thanks! @javabster 

Resolving patch:
diff --git a/qiskit/visualization/pulse_v2/plotters/matplotlib.py b/qiskit/visualization/pulse_v2/plotters/matplotlib.py
--- a/qiskit/visualization/pulse_v2/plotters/matplotlib.py
+++ b/qiskit/visualization/pulse_v2/plotters/matplotlib.py
@@ -50,6 +50,8 @@ def __init__(self, canvas: core.DrawerCanvas, axis: Optional[plt.Axes] = None):
             if not chart.is_active and not self.canvas.formatter["control.show_empty_channel"]:
                 continue
             canvas_height += chart.vmax - chart.vmin
+        # set min canvas_height size
+        canvas_height = max(canvas_height, 0.1)
 
         if axis is None:
             fig_h = canvas_height * self.canvas.formatter["general.fig_chart_height"]
@@ -164,7 +166,10 @@ def draw(self):
         )
 
         # boundary
-        self.ax.set_xlim(*axis_config.window)
+        if axis_config.window == (0, 0):
+            self.ax.set_xlim(0, 1)
+        else:
+            self.ax.set_xlim(*axis_config.window)
         self.ax.set_ylim(y_min, y_max)
 
         # title


Test patch: