Repository: spyder-ide/spyder

Issue:
Spyder switches to plot tab when debugging in console
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [x] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [ ] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [x] Tried basic troubleshooting (if a bug/error)
    * [x] Restarted Spyder
    * [ ] Reset preferences with ``spyder --reset``
    * [ ] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [ ] Tried the other applicable steps from the Troubleshooting Guide
* [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description
The Spyder UI opens the "Plots" tab when actively debugging code in the console, regardless of which tab is currently being used.


### What steps reproduce the problem?

1. Debug the following code (set break point at c=1):

```python
import matplotlib.pyplot as plt
import numpy as np

a=np.arange(0,10)
b=np.arange(0,10)

plt.plot(a,b)

c=1
```
2. Allow code to run and stop at break point
3. Either leave current tab as "Help" (or open "Variable Explorer"/"Files").
4. type c=1 into console

### What is the expected output? What do you see instead?

The expected behaviour would be to stay on the current tab. What happens instead is the "Plots" tab opens. 

When debugging code, I am most often interested in using the "Variable Explorer" tab. If I have this open and then start changing some variables in the console, I don't expect Spyder to yank me out of "Variable Explorer" and into "Plots".

As a side note, I also get the:

> Figures now render in the Plots pane by default. To make them also appear inline in the Console, uncheck "Mute Inline Plotting" under the Plots pane options menu. 

print out only after typing in the console. If this really needs to be shown, then shouldn't this happen before I type something into the console? Is this perhaps why Spyder is rudely switching tabs on me?

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 5.0.3
* Python version: 3.8.5 64-bit
* Qt version: 5.9.7
* PyQt version: 5.9.2
* Operating System name/version: Windows 10




Discussion:
Hey @Caseyb87, thanks for reporting. Did you deactivated the option called `Mute inline plotting` in the Options menu of Plots?

![imagen](https://user-images.githubusercontent.com/365293/119688430-98107600-be0d-11eb-9bf4-beb98ae527e6.png)

That's what avoids automatically showing that pane after each plot.
No, that option was enabled. 

(Otherwise I don't think the "Figures now render in the Plots pane by default. To make them also appear inline in the Console, uncheck "Mute Inline Plotting" under the Plots pane options menu." text would show - it would show the plot in the console instead)
I verified that this is the case if you're not debugging as well, which I find very annoying. I'll fix it in our 5.1.0 version, to be released in July.

Resolving patch:
diff --git a/spyder/plugins/plots/plugin.py b/spyder/plugins/plots/plugin.py
--- a/spyder/plugins/plots/plugin.py
+++ b/spyder/plugins/plots/plugin.py
@@ -34,7 +34,7 @@ class Plots(SpyderDockablePlugin):
     CONF_FILE = False
     DISABLE_ACTIONS_WHEN_HIDDEN = False
 
-    # --- SpyderDockablePlugin API
+    # ---- SpyderDockablePlugin API
     # ------------------------------------------------------------------------
     def get_name(self):
         return _('Plots')
@@ -46,9 +46,9 @@ def get_icon(self):
         return self.create_icon('hist')
 
     def on_initialize(self):
-        # If a figure is loaded raise the dockwidget but do not give focus
-        self.get_widget().sig_figure_loaded.connect(
-            lambda: self.switch_to_plugin(force_focus=False))
+        # If a figure is loaded, raise the dockwidget the first time
+        # a plot is generated.
+        self.get_widget().sig_figure_loaded.connect(self._on_first_plot)
 
     @on_plugin_available(plugin=Plugins.IPythonConsole)
     def on_ipython_console_available(self):
@@ -72,15 +72,7 @@ def unregister(self):
         ipyconsole.sig_shellwidget_deleted.connect(
             self.remove_shellwidget)
 
-    def switch_to_plugin(self, force_focus=False):
-        # Only switch when inline plotting is muted. This avoids
-        # showing the plugin when users want to only see plots in
-        # the IPython console.
-        # Fixes spyder-ide/spyder#15467
-        if self.get_conf('mute_inline_plotting'):
-            super().switch_to_plugin(force_focus=force_focus)
-
-    # --- Public API
+    # ---- Public API
     # ------------------------------------------------------------------------
     def current_widget(self):
         """
@@ -128,3 +120,19 @@ def set_shellwidget(self, shellwidget):
             The shell widget.
         """
         self.get_widget().set_shellwidget(shellwidget)
+
+    # ---- Private API
+    # ------------------------------------------------------------------------
+    def _on_first_plot(self):
+        """Actions to execute after the first plot is generated."""
+        # Only switch when inline plotting is muted. This avoids
+        # showing the plugin when users want to only see plots in
+        # the IPython console.
+        # Fixes spyder-ide/spyder#15467
+        if self.get_conf('mute_inline_plotting'):
+            self.switch_to_plugin(force_focus=False)
+
+        # We only give raise to the plugin once per session, to let users
+        # know that plots are displayed in this plugin.
+        # Fixes spyder-ide/spyder#15705
+        self.get_widget().sig_figure_loaded.disconnect(self._on_first_plot)
diff --git a/spyder/plugins/plots/widgets/figurebrowser.py b/spyder/plugins/plots/widgets/figurebrowser.py
--- a/spyder/plugins/plots/widgets/figurebrowser.py
+++ b/spyder/plugins/plots/widgets/figurebrowser.py
@@ -203,7 +203,7 @@ def setup(self, options):
 
     def update_splitter_widths(self, base_width):
         """
-        Update the widths to provide the scrollbar with a fixed minimumwidth.
+        Update the widths to provide the scrollbar with a fixed minimum width.
 
         Parameters
         ----------
diff --git a/spyder/plugins/plots/widgets/main_widget.py b/spyder/plugins/plots/widgets/main_widget.py
--- a/spyder/plugins/plots/widgets/main_widget.py
+++ b/spyder/plugins/plots/widgets/main_widget.py
@@ -173,7 +173,11 @@ def __init__(self, name=None, plugin=None, parent=None):
         self._stack.sig_save_dir_changed.connect(
             lambda val: self.set_conf('save_dir', val))
 
-    # --- PluginMainWidget API
+        # Resize to a huge width to get the right size of the thumbnail
+        # scrollbar at startup.
+        self.resize(50000, self.height())
+
+    # ---- PluginMainWidget API
     # ------------------------------------------------------------------------
     def get_title(self):
         return _('Plots')
@@ -359,7 +363,7 @@ def on_section_conf_change(self, option, value):
                 widget.setup({option: value})
                 self.update_actions()
 
-    # --- Public API:
+    # ---- Public API:
     # ------------------------------------------------------------------------
     def set_current_widget(self, fig_browser):
         """


Test patch: