Search code examples
pythonpandasmatplotlibcalendar

how to display a title on a calendar heatmap using calplot?


I am trying to save a calplot image but I can't seem to display the title. Following the documentation, I need to use the property: suptitle.

import calplot
import pylab
import numpy as np; np.random.seed(sum(map(ord, 'calplot')))
import pandas as pd
all_days = pd.date_range('1/1/2019', periods=730, freq='D')
days = np.random.choice(all_days, 500)
events = pd.Series(np.random.randn(len(days)), index=days)
calplot.calplot(
    events, 
    figsize=(20,4),
    suptitle='lorem ipsum',
    cmap='Spectral_r',
    )
pylab.savefig('foo.png')

Above is the minimal code found in the documentation. I am using pylab to save the image on my drive Calplot image

I can barely notice the title. How can I show the title? I am using Windows and Continuum Anaconda as stack


Solution

  • Increase the font size

    fontsize=20
    
    
    import calplot
    import pylab
    import numpy as np; np.random.seed(sum(map(ord, 'calplot')))
    import pandas as pd
    all_days = pd.date_range('1/1/2019', periods=730, freq='D')
    days = np.random.choice(all_days, 500)
    events = pd.Series(np.random.randn(len(days)), index=days)
    
    fig = calplot.calplot(
        events, 
        figsize=(20,4),
        cmap='Spectral_r',
        )
    fig.suptitle('lorem ipsum', fontsize=20)
    pylab.savefig('foo.png')
    

    Updated with fig defined