Created
June 27, 2012 23:58
-
-
Save ptweir/3007721 to your computer and use it in GitHub Desktop.
functions for plotting mean or mean and sem of numpy array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def binMeanPlot(X,Y,ax=None,numBins=8,xmin=None,xmax=None): | |
| if xmin is None: | |
| xmin = X.min() | |
| if xmax is None: | |
| xmax = X.max() | |
| if ax is None: | |
| fig = pylab.figure() | |
| ax = fig.add_subplot(111) | |
| bins = np.linspace(xmin,xmax,numBins+1) | |
| XX = np.array([np.mean((bins[binInd], bins[binInd+1])) for binInd in range(numBins)]) | |
| YY = np.array([np.mean(Y[(X > bins[binInd]) & (X <= bins[binInd+1])]) for binInd in range(numBins)]) | |
| lineHandles = ax.plot(XX,YY) | |
| return lineHandles[0], XX, YY | |
| def binMeanStdPlot(X,Y,ax=None,numBins=8,xmin=None,xmax=None): | |
| if xmin is None: | |
| xmin = X.min() | |
| if xmax is None: | |
| xmax = X.max() | |
| if ax is None: | |
| fig = pylab.figure() | |
| ax = fig.add_subplot(111) | |
| bins = np.linspace(xmin,xmax,numBins+1) | |
| XX = np.array([np.mean((bins[binInd], bins[binInd+1])) for binInd in range(numBins)]) | |
| YY = np.array([np.mean(Y[(X > bins[binInd]) & (X <= bins[binInd+1])]) for binInd in range(numBins)]) | |
| #XX[np.isnan(YY)]=np.nan | |
| YYstd = np.array([np.std(Y[(X > bins[binInd]) & (X <= bins[binInd+1])]) for binInd in range(numBins)]) | |
| lineHandles = ax.plot(XX,YY) | |
| patchHandle = ax.fill_between(XX[~np.isnan(YY)],YY[~np.isnan(YY)]-YYstd[~np.isnan(YY)],YY[~np.isnan(YY)]+YYstd[~np.isnan(YY)]) | |
| patchHandle.set_facecolor([.8, .8, .8]) | |
| patchHandle.set_edgecolor('none') | |
| return lineHandles[0], patchHandle, XX, YY, YYstd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment