I am trying to make QQ-plots using the statsmodel package. However, the resolution of the figure is so low that I could not possibly use the results in a presentation.
I know that to make networkX graph plot a higher resolution image I can use:
plt.figure( figsize=(N,M) )
networkx.draw(G)
and change the values of N and M to attain desirable results.
However, when I try the same method with a QQ-plot from the statsmodel package, it seems to have no impact on the size of the resulting figure, i.e., when I use
plt.Figure( figsize = (N,M) )
statsmodels.qqplot_2samples(sample1, sample2, line = 'r')
changing M and N have no effect on the figure size. Any ideas on how to fix this (and why this method isn't working)?
You can use mpl.rc_context
to temporarily set the default figsize
before plotting.
import numpy as np
import matplotlib as mpl
from statsmodels.graphics.gofplots import qqplot_2samples
np.random.seed(10)
sample1 = np.random.rand(10)
sample2 = np.random.rand(10)
n, m = 6, 6
with mpl.rc_context():
mpl.rc("figure", figsize=(n,m))
qqplot_2samples(sample1, sample2, line = 'r')
This is a great solution and works for other plots too - I upvoted it. Here is the implementation for acf and pacf plots.
N, M = 12, 6
fig, ax = plt.subplots(figsize=(N, M))
plot_pacf(df2, lags = 40, title='Daily Female Births', ax=ax)
plt.show()
The qqplot_2samples
function has an ax
parameter which allows you to specify
a matplotlib axes object on which the plot should be drawn. If you don't supply
the ax
, then a new axes object is created for you.
So, as an alternative to cel's solution, if you wish to create your own figure,
then you should also pass the figure's axes object to qqplot_2samples
:
sm.qqplot_2samples(sample1, sample2, line='r', ax=ax)
For example,
import scipy.stats as stats
import matplotlib.pyplot as plt
import statsmodels.api as sm
N, M = 6, 5
fig, ax = plt.subplots(figsize=(N, M))
sample1 = stats.norm.rvs(5, size=1000)
sample2 = stats.norm.rvs(10, size=1000)
sm.qqplot_2samples(sample1, sample2, line='r', ax=ax)
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With