How can I make a blank subplot in matplotlib?

前端 未结 4 523
长发绾君心
长发绾君心 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 13:52

    It's also possible to hide a subplot using the Axes.set_visible() method.

    import matplotlib.pyplot as plt
    import pandas as pd
    
    fig = plt.figure()
    data = pd.read_csv('sampledata.csv')
    
    for i in range(0,6):
    ax = fig.add_subplot(3,2,i+1)
    ax.plot(range(1,6), data[i])
    if i == 5:
        ax.set_visible(False)
    

提交回复
热议问题