简体   繁体   中英

Python: multiple qqplot in statsmodel

I'm new to python. At moment, I'm trying to do qqplot in statsmodels, with data from a csv file. No idea on how to upload data file, so I capture part of it as picture. Here is the head part ofdata from csv . I want to plot multiple qqplots on one page with 2x2 style, but cannot get the plots correct. Having done much research, I think if it would be much helpful if people could give me some hints or tell me where the problem is.

    import numpy as np
    import pandas as pd
    import scipy.stats as scs
    import statsmodels.api as sm
    from pylab import plt
    plt.style.use('ggplot')
    import matplotlib as mpl

    symbols = ['SPY', 'GLD', 'AAPL.O', 'MSFT.O']
    raw = pd.read_csv('tr_eikon_eod_data.csv',
                    index_col=0, parse_dates=True)
    data = raw[symbols]
    data = data.dropna()
    log_returns = np.log(data / data.shift(1))


    fig, ax = plt.subplots(2, 2, figsize=(6,4))
       for sym in symbols:
          sm.qqplot(log_returns[sym].dropna(),line='s',ax=ax[sym])


    plt.grid(True)
    plt.xlabel('theoretical quantiles')
    plt.ylabel('sample quantiles')
    plt.title(sym)

    plt.show   

enter image description here apparently I cannot review the picture I have uploaded

This will create 2by2 plot (2 rows, 2 columns), haven't figured out how to add title for each plot tough. Basecially, take advantage of matplotlib.pyplot.figure properties.

import statsmodels.api as sm
import pylab

figure, axes = plt.subplots(2, 2, figsize=(10,8))

sm.qqplot(df.col_name1, line='s', ax = axes[0, 0])
sm.qqplot(numpy.ndarray, line='s', ax = axes[0, 1])
sm.qqplot(series3, line='s', ax = axes[1, 0])
sm.qqplot(df.col_name2, line='s', ax = axes[1, 1])
figure.suptitle('Multiple qq plots', fontsize=14, fontweight='bold')
plt.tight_layout()
plt.show()
#pylab.show()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM