Advertisement
elena1234

How to add many axes with Matplotlib in Python

Apr 26th, 2022 (edited)
685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3.  
  4. x = np.arange(1,10)
  5. y = x ** 4
  6.  
  7. fig = plt.figure(figsize = (10,8), dpi=400)
  8. axes1 = fig.add_axes([0,0,2,2])
  9. axes1.plot(x,y, label = 'X vs X', color = 'green', marker = 'o', markersize = 10, markerfacecolor = 'red', linestyle ='-.')
  10.  
  11. axes1.set_xlim(0,8)
  12. axes1.set_ylim(0,8000)
  13. axes1.set_xlabel("X label")
  14. axes1.set_ylabel("Y label")
  15. axes1.set_title("String title")
  16. axes1.legend()
  17.  
  18.  
  19. a = np.arange(1,5)
  20. b = a * 100
  21.  
  22. axes2 = fig.add_axes([0.3,0.3, 0.6,0.6])
  23. axes2.plot(a,b, label = 'Label', color = 'blue')
  24.  
  25. axes2.set_xlim(1,2)
  26. axes2.set_ylim(0,500)
  27. axes2.set_xlabel("X label")
  28. axes2.set_ylabel("Y label")
  29. axes2.set_title("String title")
  30. axes2.legend(loc = 'lower right') # locate the label
  31. # axes2.legend(loc = (1.1,0.5)) # outside
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement