title: How can I display a graph in a new window? Tkinter GUI
body: <p>Here is the code for my graph function and a sample function to open a new window. I couldn't find how to print my graph on a new window. I tried alternatives to this but only found myself able to commit both commands separately. Any idea how I can print my graph on a new window?</p>
  <pre><code>def plot(): 
      # the figure that will contain the plot 
      fig = Figure(figsize = (5, 5), dpi = 100) 
      df = pd.DataFrame(np.random.randint(0,1000,size=(20, 2)), columns= 
      ('Storage Units (kWh)', 'Power Plants (kW)'))
      y = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)
      fig, axes = plt.subplots(ncols=2, sharey=True)
      plt.suptitle('Optimal Actions')
      plt.yticks(np.arange(min(y), max(y)+1, 1.0))
      axes[0].invert_yaxis
      axes[0].xaxis.set_label_position('top') 
      axes[1].xaxis.set_label_position('top')
      axes[0].yaxis.set_label_coords(1.15,1.02)
      axes[0].barh(y, df['Storage Units (kWh)'], align='center', color='red')
      axes[1].barh(y, df['Power Plants (kW)'], align='center', color='blue')
      axes[0].invert_xaxis()
      axes[0].yaxis.tick_right()
      axes[0].set_xlabel('Storage Units (kWh)')
      axes[1].set_xlabel('Power Plants (kW)')
      axes[0].set_ylabel('Year')
      # creating the Tkinter canvas 
      # containing the Matplotlib figure 
      canvas = FigureCanvasTkAgg(fig, master = window)   
      canvas.draw() 
      # placing the canvas on the Tkinter window 
      canvas.get_tk_widget().pack() 
  def create_window():
      newwindow = tk.Toplevel(window)
  pbutton = tk.Button(frame4,
                      text = &quot;Plot&quot;,
                      command = lambda:[create_window(), plot()]).pack(side = 
  &quot;right&quot;)
  </code></pre>