add title to collection of pandas hist plots

后端 未结 4 944
盖世英雄少女心
盖世英雄少女心 2020-12-23 16:29

I\'m looking for advice on how to show a title at the top of a collection of histogram plots that have been generated by a pandas df.hist() command. For instance, in the his

相关标签:
4条回答
  • 2020-12-23 17:03

    With newer Pandas versions, if someone is interested, here a slightly different solution with Pandas only:

    ax = data.plot(kind='hist',subplots=True,sharex=True,sharey=True,title='My title')
    
    0 讨论(0)
  • 2020-12-23 17:09

    for matplotlib.pyplot, you can use:

    import matplotlib.pyplot as plt
    # ...
    plt.suptitle("your title")
    

    or if you're using a Figure object directly,

    import matplotlib.pyplot as plt
    fig, axs = plt.subplots(...)
    # ...
    fig.suptitle("your title")
    

    See this example.

    0 讨论(0)
  • 2020-12-23 17:13

    You can use suptitle():

    import pylab as pl
    from pandas import *
    data = DataFrame(np.random.randn(500).reshape(100,5), columns=list('abcde'))
    axes = data.hist(sharey=True, sharex=True)
    pl.suptitle("This is Figure title")
    
    0 讨论(0)
  • 2020-12-23 17:14

    I found a better way:

    plt.subplot(2,3,1)  # if use subplot
    df = pd.read_csv('documents',low_memory=False)
    df['column'].hist()
    plt.title('your title')
    

    It is very easy, display well at the top, and will not mess up your subplot.

    0 讨论(0)
提交回复
热议问题