How can I make a blank subplot in matplotlib?

前端 未结 4 521
长发绾君心
长发绾君心 2020-12-04 13:02

I am making a group of subplot (say, 3 x 2) in matplotlib, but I have fewer than 6 datasets. How can I make the remaining subplot blank?

The arrangement looks like t

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-04 14:02

    Would it be an option to create the subplots when you need them?

    import matplotlib
    matplotlib.use("pdf")
    import matplotlib.pyplot as plt
    
    plt.figure()
    plt.gcf().add_subplot(421)
    plt.fill([0,0,1,1],[0,1,1,0])
    plt.gcf().add_subplot(422)
    plt.fill([0,0,1,1],[0,1,1,0])
    plt.gcf().add_subplot(423)
    plt.fill([0,0,1,1],[0,1,1,0])
    plt.suptitle("Figure Title")
    plt.gcf().subplots_adjust(hspace=0.5,wspace=0.5)
    plt.savefig("outfig")
    

提交回复
热议问题