Create a gist now

Instantly share code, notes, and snippets.

anonymous /faq_subplot-del-lines
Created Dec 18, 2010

It helps in deleting lines in a subplot
*** 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment