daily pastebin goal
53%
SHARE
TWEET

Untitled

a guest Feb 19th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import tkinter as tk
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. from matplotlib.backends.backend_pdf import PdfPages
  5. from pathlib import Path
  6.  
  7. class Pdf(object):
  8.     def __init__(self, master):
  9.         self.root = master
  10.         pdf = PdfPages(Path.cwd() / 'demo.pdf')
  11.  
  12.         self.pdf = pdf
  13.  
  14.     def plot_initial(self):
  15.         fig = plt.figure(figsize=(8,6))
  16.         fig.add_subplot(111)
  17.  
  18.         mu, sigma = 0, 0.1
  19.         s = np.random.normal(mu, sigma, 1000)
  20.         count, bins, ignored = plt.hist(s, 30, density=True)
  21.         plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) *
  22.                  np.exp( - (bins - mu)**2 / (2 * sigma**2) ),
  23.                  linewidth=2, color='r')
  24.         plt.title('Overview')
  25.         plt.xlabel('X')
  26.         plt.ylabel('Y')
  27.         self.pdf.savefig(fig)
  28.         # THE CULPRIT
  29.         plt.close(fig)
  30.  
  31.     def plot_extra(self):
  32.         fig = plt.figure(figsize=(8,6))
  33.         fig.add_subplot(111)
  34.  
  35.         mu, sigma = 0, 0.1
  36.         s = np.random.normal(mu, sigma, 1000)
  37.         count, bins, ignored = plt.hist(s, 30, density=True)
  38.         plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) *
  39.                  np.exp( - (bins - mu)**2 / (2 * sigma**2) ),
  40.                  linewidth=2, color='r')
  41.         plt.title('Extra')
  42.         plt.xlabel('X')
  43.         plt.ylabel('Y')
  44.         self.pdf.savefig(fig)
  45.         plt.close(fig)
  46.  
  47.     def close(self):
  48.         self.pdf.close()
  49.  
  50. class MVE(object):
  51.     @classmethod
  52.     def run(cls):
  53.         root = tk.Tk()
  54.         MVE(root)
  55.         root.mainloop()
  56.  
  57.     def __init__(self, master):
  58.         self.root = master
  59.         tk.Frame(master)
  60.  
  61.         menu = tk.Menu(master)
  62.         master.config(menu=menu)
  63.  
  64.         test_menu = tk.Menu(menu, tearoff=0)
  65.         menu.add_cascade(label='Bug', menu=test_menu)
  66.         test_menu.add_command(label='PDF', command=
  67.                               self.generate_pdf)
  68.  
  69.     def generate_pdf(self):
  70.         pdf = Pdf(self)
  71.  
  72.         pdf.plot_initial()
  73.         for i in range(0,3):
  74.             pdf.plot_extra()
  75.         pdf.close()
  76.  
  77. if __name__ == "__main__":
  78.     MVE.run()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top