0

I have a python program (not a notebook, a python file) where I produce several plots that show up one after the other. The program looks something like this:

import numpy as np
import matplotlib.pyplot as plt

functions = [np.sin, np.cos, np.abs, np.square]

x = np.linspace(-np.pi, np.pi, 100)
for func in functions:
    plt.plot(x, func(x))
    plt.show()

When I run the program in vscode I have to close one plot before the next one opens. The windows with the plots open at different locations every time and it would be more convenient if the X button was at the same place every time so i can click through them more easily. Is there a way to do this?

rioV8
  • 24,506
  • 3
  • 32
  • 49
munichmath
  • 65
  • 6

1 Answers1

0

I solved it like this:

import numpy as np
import matplotlib.pyplot as plt
from pylab import get_current_fig_manager

functions = [np.sin, np.cos, np.abs, np.square]
x = np.linspace(-np.pi, np.pi, 100)
for func in functions:
    thismanager = get_current_fig_manager()
    thismanager.window.wm_geometry("+500+0")
    plt.plot(x, func(x))
    plt.show()

Like on this webpage: https://pyquestions.com/how-do-you-set-the-absolute-position-of-figure-windows-with-matplotlib or as answered here: How do you set the absolute position of figure windows with matplotlib?. I thought it was a vscode issue but everything is done by matplotlib. If anyone knows a more permanent solution, please let me know, as setting this for every plot is quite annoying.

munichmath
  • 65
  • 6