Advertisement
ivan866

Untitled

Jan 15th, 2024
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.13 KB | Source Code | 0 0
  1. #!/usr/bin/env python
  2. #coding: utf8
  3.  
  4. import numpy as np
  5.  
  6. import matplotlib
  7. import matplotlib.pyplot as plt
  8. import matplotlib.pylab as pylab
  9.  
  10. matplotlib.rcParams['backend'] = "TkAgg"
  11. matplotlib.style.use('bmh')
  12. params = {'axes.titlesize': 'small', 'axes.titleweight': 'normal',
  13.           'axes.labelsize': 'small', 'axes.labelweight': 'normal',
  14.           'axes.facecolor': '#ffffff',
  15.           'axes.grid': True,
  16.           'axes.grid.which': 'both',
  17.           'xtick.labelsize': 'x-small', 'ytick.labelsize': 'x-small',
  18.           'xtick.direction': 'out', 'ytick.direction': 'out',
  19.           'ytick.left': True, 'xtick.bottom': True,
  20.           'ytick.minor.left': True, 'xtick.minor.bottom': True,
  21.           'xtick.minor.visible': True, 'ytick.minor.visible': True,
  22.           }
  23. pylab.rcParams.update(params)
  24.  
  25.  
  26. figure = plt.figure(figsize=(29.7/2.54, 21.0/2.54))
  27.  
  28. ##001
  29. def foo(xs:np.ndarray) -> np.ndarray:
  30.     return(3 - np.cos(xs))
  31. xs = np.linspace(0, 6*np.pi, num=250)
  32. ys = foo(xs - 3 * np.sin(xs))
  33.  
  34. figure.add_subplot(3,1,1)
  35. ax = figure.gca(); ax.set_aspect('equal')
  36. ax.set_title('Циклоида')
  37. ax.set_xlabel('x'); ax.set_ylabel('y')
  38. ax.set_xlim(np.min(xs) - .1, np.max(xs) + .1); ax.set_ylim(np.min(ys) - .1, np.max(ys) + .1)
  39.  
  40. ax.plot(xs, ys, '--', color=(.2,.85,0), alpha=.35, linewidth=1)
  41. ax.text(.1, np.max(ys), 'Вот такая моя функция',
  42.         fontsize=11, fontweight='light', family='monospace',
  43.         horizontalalignment='left', verticalalignment='top')
  44.  
  45. ##002
  46. xs = np.random.normal(0, 1, 3000)
  47. ys = np.random.normal(3, 4, 3000)
  48.  
  49. figure.add_subplot(3,1,2)
  50. ax = figure.gca()
  51. ax.set_title('Scatter')
  52. ax.set_xlabel('x'); ax.set_ylabel('y')
  53. ax.set_xlim(np.min(xs) - .1, np.max(xs) + .1); ax.set_ylim(np.min(ys) - .1, np.max(ys) + .1)
  54. ax.scatter(xs, ys, c=(.8,0,0), s=4, marker='<', alpha=.35)
  55.  
  56. ##003
  57. data = np.random.normal(16, 2, 1000)
  58.  
  59. figure.add_subplot(3,1,3)
  60. ax = figure.gca()
  61. ax.hist(data, bins=100, color=(1,0,0,.6))
  62.  
  63. figure.show()
  64. figure.savefig('plot01.{:s}'.format('png'), format='png',
  65.                facecolor='white', dpi=300, bbox_inches='tight')
  66. figure.clf(); del(figure)
Tags: matplotlib
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement