Repository: spyder-ide/spyder

Issue:
Blank line printed on console for each chart plotted
Small issue: an extra blank line is printed on the console every time I print a chart. You can see below on the Plots pane that I have plotted a few charts. Although there is no "print"  function on the section of the code that prints the charts, a new blank line is printed every time I new chart is plotted. Again, not a big issue but it messes up with the console formatting if the code prints some info during execution (which I always do).

![Annotation 2019-12-01 121346](https://user-images.githubusercontent.com/57544001/69917437-0ef4ca80-1434-11ea-8a13-7b02a3937847.jpg)



Discussion:
This is not a problem in Spyder but in your code. To verify it, you can simply do

```python
import matplotlib.pyplot as plt
plt.plot(range(10))
```

and you'll see that no new line is printed.
Maybe it is the plt.show() function that triggers it? Look below at what I get when running the code below:

import matplotlib.pyplot as plt

for x in range(10):
    print ("Plot #{0:0f}:".format(x))
    plt.plot(range(2*x+2))
    plt.show()

The line between the figure numbers shouldn't be there, correct?

![Annotation 2019-12-01 141358](https://user-images.githubusercontent.com/57544001/69918863-db6e6c00-1444-11ea-9be0-bd065c9fb583.jpg)

> Maybe it is the plt.show() function that triggers it?

Yes, that's it. You don't need that command when running your code in Spyder.
It is definitively the plt.show() command. However, if I eliminate the plt.show() command, I only see the last plot, correct? I.e. see below what I get on the Plots pane without / with the plt.show() command on the simple test code. 

I also plot various charts with subplots - and I guess the only way to show them is, at the end of the code, use plt.show(). Maybe there is another way to show the various plots without plt.show() that I'm not aware of? At the end of this response, please see a chart with four subplots. The code has to end with plt.show() otherwise I don't see them on the Plots pane.

Without plt.show(): only one chart on the side-bar
![Annotation 2019-12-01 142810](https://user-images.githubusercontent.com/57544001/69919046-d7434e00-1446-11ea-8576-468181dc5add.jpg)

With plt.show(): all ten charts on the side-bar
![Annotation 2019-12-01 142959](https://user-images.githubusercontent.com/57544001/69919068-14a7db80-1447-11ea-980a-609b67d5bc56.jpg)

Sample chart with various subplots:
![sdfsdf](https://user-images.githubusercontent.com/57544001/69919189-5422f780-1448-11ea-9695-00df07767e41.png)

Well, as you said, this is a very minor thing and not even something we can fix here, sorry.
Totally agree - the issue is a minor one. I wish we had a "character" we could use in Python, in general, that would allow us to move the cursor up one line. That would make the console a much more user-friendly window.
> 
> 
> This is not a problem in Spyder but in your code. To verify it, you can simply do
> 
> ```python
> import matplotlib.pyplot as plt
> plt.plot(range(10))
> ```
> 
> and you'll see that no new line is printed.

Actually, yes a new line is printed when I run the code above. There is two blank lines instead of one.
@ccordoba12 I think this can be fixed on our end. This happens because of the `mute_inline_plotting` option. I can take a look at it if you want.
> This happens because of the mute_inline_plotting option. I can take a look at it if you want.

On Linux I only see a an extra line the first time a plot is generated. After that I see none.

So maybe this is a Windows only issue?
> 
> 
> > This happens because of the mute_inline_plotting option. I can take a look at it if you want.
> 
> On Linux I only see a an extra line the first time a plot is generated. After that I see none.
> 
> So maybe this is a Windows only issue?

hmmm maybe, but I really don't understand why... The extra line is added in the qtconsole at the end of `_handle_display_data`  with `self._append_plain_text(u'\n', True)`:

https://github.com/jupyter/qtconsole/blob/2379cb7903730de343a917ceb91edf8bfde2659e/qtconsole/jupyter_widget.py#L275-L290

Ususally, the rich jupyter widget eats the messages when there is an image in the data.

https://github.com/jupyter/qtconsole/blob/2379cb7903730de343a917ceb91edf8bfde2659e/qtconsole/rich_jupyter_widget.py#L155-L183

However, we are deleting the image from the data in `_handle_display_data` of the figure browser widget when `mute_inline_plotting` is True. Therefore, the message is not eaten by the rich jupyter widget and an empty string is passed to the normal jupyter widget who adds a `\n` at the end.

So to fix this issue, I think that we simply need to eat the message in the figure browser widget when we detect an image in the data and `mute_inline_plotting` is True and not pass it to the rich jupyter widget.
I'll submit a PR with a proposed fix and we can discuss it over there if you want.

Resolving patch:
diff --git a/spyder/plugins/ipythonconsole/widgets/figurebrowser.py b/spyder/plugins/ipythonconsole/widgets/figurebrowser.py
--- a/spyder/plugins/ipythonconsole/widgets/figurebrowser.py
+++ b/spyder/plugins/ipythonconsole/widgets/figurebrowser.py
@@ -53,12 +53,12 @@ def _handle_display_data(self, msg):
         elif 'image/jpeg' in data and self._jpg_supported:
             fmt = 'image/jpeg'
             img = decodebytes(data['image/jpeg'].encode('ascii'))
+
         if img is not None:
             self.sig_new_inline_figure.emit(img, fmt)
             if (self.figurebrowser is not None and
                     self.figurebrowser.mute_inline_plotting):
                 if not self.sended_render_message:
-                    msg['content']['data']['text/plain'] = ''
                     self._append_html(
                         _('<br><hr>'
                           '\nFigures now render in the Plots pane by default. '
@@ -67,8 +67,5 @@ def _handle_display_data(self, msg):
                           'pane options menu. \n'
                           '<hr><br>'), before_prompt=True)
                     self.sended_render_message = True
-                else:
-                    msg['content']['data']['text/plain'] = ''
-                del msg['content']['data'][fmt]
-
+                return
         return super(FigureBrowserWidget, self)._handle_display_data(msg)


Test patch: