Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete a subplot

I'm trying to figure out a way of deleting (dynamically) subplots in matplotlib. I see they have a remove method, but I get the error

NotImplementedError: cannot remove artist 

I'm surprised that I can't find this anywhere. Does anyone know how to do this?

from matplotlib import pyplot as plt  fig, axs = plt.subplots(1,3)  axs[0].plot([1,2],[3,4]) axs[2].plot([0,1],[2,3])  plt.draw() plt.tight_layout() 

enter image description here

like image 403
Jeff Avatar asked Feb 04 '13 19:02

Jeff


People also ask

How do I remove the subplot in Axis?

We can turn off the axes of subplots in Matplotlib using axis() and set_axis_off() methods for axes objects. We can also turn off axes using the axis() method for the pyplot object. To turn off axis for X-axis in particular we use axes. get_xaxis().


1 Answers

Use fig.delaxes or plt.delaxes to remove unwanted subplots

fig, axs = plt.subplots(1,3) axs[0].plot([1,2],[3,4]) axs[2].plot([0,1],[2,3])  fig.delaxes(axs[1])  plt.draw() plt.tight_layout() 

enter image description here

like image 61
Jeff Avatar answered Oct 02 '22 08:10

Jeff