public
anonymous / faq_subplot-del-lines
Created

It helps in deleting lines in a subplot

  • Download Gist
faq_subplot-del-lines
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
*** howto_faq.rst 2010-10-20 00:29:55.000000000 +0530
--- howto_faq_sub.rst 2010-12-18 13:12:37.000000000 +0530
***************
*** 97,102 ****
--- 97,131 ----
pp.close()
+ .. _howto-subplots-delete
+
+ Delete lines from subplots
+ -------------------------------
+
+ If you have have multiple-lines in subplots and would like to add or delete lines in various subplots, a good approach is to save the subplots into the objects. Later access them using the objects into which they have been copied into::
+
+ import numpy as np
+ import matplotlib.pyplot as plt
+
+ fig = plt.figure()
+ sub1 = fig.add_subplot(211) # passing subplot(211) into sub1
+ x = np.linspace(0, 50, 500)
+ sub1.plot(x, np.cos(x*x), 'b-') # plotting on current subplot
+ sub1.set_xlabel(r'$x$')
+ sub1.set_ylabel(r'$y$')
+ sub2 = fig.add_subplot(212) # passing subplot(212) into sub2
+ sub2.plot(x, np.sin(3*x), 'r-') # plotting on subplot(212)
+ sub2.plot(x, np.sin(x)*np.cos(4*x), 'k-')
+ sub2.set_ylabel(r'$y$')
+
+ # now to add a line in subplot(211)
+ sub1.plot(x,np.cos(x), 'g-' )
+ plt.show()
+
+ # delete a line from subplot(212)
+ del sub2.lines[1]
+ plt.draw()
+
.. _howto-subplots-adjust:
Move the edge of an axes to make room for tick labels

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.