Advertisement
MdSadmanSiraj

python_plots_template.py

Dec 3rd, 2022
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.67 KB | None | 0 0
  1. # Libraries
  2. import numpy as np
  3. from matplotlib import rcParams, pyplot as plt
  4. import random
  5.  
  6. # Plot parameters
  7. def plot_params():
  8.     params = {
  9.        'font.family' : 'sans-serif',
  10.        'font.sans-serif' : 'Calibri',
  11.        'axes.labelsize': 24,
  12.        'axes.labelweight': "bold",
  13.        'axes.titlesize': 24,
  14.        'axes.titleweight': "bold",
  15.        'font.size': 24,
  16.        'font.weight': "bold",
  17.        'legend.fontsize': 24,
  18.        'xtick.labelsize': 24,
  19.        'ytick.labelsize': 24,
  20.        'text.usetex': False,
  21.        'figure.figsize': [6*1.5, 3.7082*1.5]
  22.        }
  23.     rcParams.update(params)
  24.    
  25. plot_params()
  26.  
  27. # Data
  28. data_1 = random.sample(range(1, 100), 20)
  29. data_2 = random.sample(range(1, 200), 20)
  30. data_3 = random.sample(range(1, 300), 20)
  31.  
  32. # Plot
  33. fig = plt.figure()
  34. ax = fig.add_subplot()
  35. plt.plot(np.sort(data_1), color = 'red', label = "data 1", marker = 'o', markersize = 8, linestyle = 'solid', linewidth = 3)
  36. plt.plot(np.sort(data_2), color = 'green', label = "data 2", marker = 'o', markersize = 8, linestyle = 'solid', linewidth = 3)
  37. plt.plot(np.sort(data_3), color = 'mediumblue', label = "data 3", marker = 'o', markersize = 8, linestyle = 'solid', linewidth = 3)
  38. plt.xlabel("Data Points", fontsize=24)
  39. plt.ylabel("Data Values", fontsize=24)
  40. plt.xticks([0, 4, 9, 14, 19], [1, 5, 10, 15, 20])
  41. plt.text(0.02, 0.95, '(a)', transform=ax.transAxes, fontsize=24, fontweight='bold', va='top')
  42. plt.legend(prop={'size': 24}, loc='upper left', bbox_to_anchor=(0.07, 0., 0.92, 1.02))
  43. plt.savefig("python_graph.png", format='png', bbox_inches='tight', dpi=720)
  44. plt.savefig("python_graph.eps", format='eps', bbox_inches='tight', dpi=720)
  45. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement