|
1 |
| -'''Scatterplot of normally distributed data, with Standard Deviation and Standard Error''' |
2 |
| - |
3 |
| -# Copyright(c) 2015, Thomas Haslwanter. All rights reserved, under the CC BY-SA 4.0 International License |
4 |
| - |
5 |
| -# Import standard packages |
6 |
| -import numpy as np |
7 |
| -import matplotlib.pyplot as plt |
8 |
| -from scipy import stats |
9 |
| -import seaborn as sns |
10 |
| - |
11 |
| -# additional packages |
12 |
| -# Import formatting commands if directory "Utilities" is available |
13 |
| -import os |
14 |
| -import sys |
15 |
| -sys.path.append(os.path.join('..', 'Code_Quantlets', 'Utilities')) |
16 |
| -try: |
17 |
| - from ISP_mystyle import setFonts, showData |
18 |
| - |
19 |
| -except ImportError: |
20 |
| -# Ensure correct performance otherwise |
21 |
| - def setFonts(*options): |
22 |
| - return |
23 |
| - def showData(*options): |
24 |
| - plt.show() |
25 |
| - return |
26 |
| - |
27 |
| -from F7_10_roc import arrow_bidir |
28 |
| - |
29 |
| -# Generate the data |
30 |
| -np.random.seed(123) |
31 |
| -x = np.random.randn(100) + 5 |
32 |
| - |
33 |
| -# Calculate "standard devation" and "standard error" locations |
34 |
| -sdVal = np.std(x, ddof=1) |
35 |
| -seVal = stats.sem(x) |
36 |
| -sd = np.mean(x) + sdVal*np.r_[-1, 1] |
37 |
| -se = np.mean(x) + seVal*np.r_[-1, 1] |
38 |
| - |
39 |
| -# Set up the plot |
40 |
| -sns.set_style('ticks') |
41 |
| -sns.set_context('poster') |
42 |
| -setFonts() |
43 |
| - |
44 |
| -# Plot the data |
45 |
| -plt.plot(x,'.') |
46 |
| -plt.axhline(np.mean(x), color=0.7*np.ones(3)) |
47 |
| -plt.axhline(sd[0], ls='--') |
48 |
| -plt.axhline(sd[1], ls='--') |
49 |
| - |
50 |
| -# Lines for SEM |
51 |
| -lh = [] |
52 |
| -lh.append( plt.axhline(se[0], ls='--', color='r') ) |
53 |
| -lh.append( plt.axhline(se[1], ls='--', color='r') ) |
54 |
| - |
55 |
| -# make the lines long-dashed |
56 |
| -dashes = [20, 5] # 20 points on, 5 off |
57 |
| -for ii in range(len(lh)): |
58 |
| - lh[ii].set_dashes(dashes) |
59 |
| - |
60 |
| -curAxis = plt.gca() |
61 |
| -curAxis.set_xticklabels( () ) |
62 |
| - |
63 |
| -# Make the arrows |
64 |
| -plt.arrow(10, np.mean(x), 0, sdVal, |
65 |
| - width=0.2, length_includes_head=True, head_length=0.2, head_width=1, color='k') |
66 |
| -plt.arrow(10, np.mean(x), 0, -sdVal, |
67 |
| - width=0.2, length_includes_head=True, head_length=0.2, head_width=1, color='k') |
68 |
| - |
69 |
| -plt.arrow(35, np.mean(x)-4*seVal, 0, 3*seVal, |
70 |
| - width=0.2, length_includes_head=True, head_length=0.1, head_width=1, color='k') |
71 |
| -plt.arrow(35, np.mean(x)+4*seVal, 0, -3*seVal, |
72 |
| - width=0.2, length_includes_head=True, head_length=0.1, head_width=1, color='k') |
73 |
| - |
74 |
| -#plt.text(10, 5.5, '$\pm$ 1SD', family='sans-seriv', fontsize=28) |
75 |
| -#plt.text(35, 5.2, '$\pm$ 1SEM', family='sans-seriv', fontsize=28) |
76 |
| -plt.text(10, 5.5, '$\pm$ 1SD', fontsize=28) |
77 |
| -plt.text(35, 5.2, '$\pm$ 1SEM', fontsize=28) |
78 |
| -plt.annotate('mean', (70,np.mean(x)),xycoords='data', fontsize=28, |
79 |
| - xytext=(75, 5.5), textcoords='data', |
80 |
| - arrowprops=dict(facecolor='black', shrink=0.05)) |
81 |
| - |
82 |
| - |
83 |
| -# Add the text |
84 |
| - |
85 |
| - |
86 |
| -# Save and show |
87 |
| -outFile = ('standardError.png') |
88 |
| -showData(outFile) |
| 1 | +'''Scatterplot of normally distributed data, with Standard Deviation and Standard Error''' |
| 2 | + |
| 3 | +# Copyright(c) 2015, Thomas Haslwanter. All rights reserved, under the CC BY-SA 4.0 International License |
| 4 | + |
| 5 | +# Import standard packages |
| 6 | +import numpy as np |
| 7 | +import matplotlib.pyplot as plt |
| 8 | +from scipy import stats |
| 9 | +import seaborn as sns |
| 10 | + |
| 11 | +# additional packages |
| 12 | +# Import formatting commands if directory "Utilities" is available |
| 13 | +import os |
| 14 | +import sys |
| 15 | +sys.path.append(os.path.join('..', 'Code_Quantlets', 'Utilities')) |
| 16 | +try: |
| 17 | + from ISP_mystyle import setFonts, showData |
| 18 | + |
| 19 | +except ImportError: |
| 20 | +# Ensure correct performance otherwise |
| 21 | + def setFonts(*options): |
| 22 | + return |
| 23 | + def showData(*options): |
| 24 | + plt.show() |
| 25 | + return |
| 26 | + |
| 27 | +from F7_10_roc import arrow_bidir |
| 28 | + |
| 29 | +# Generate the data |
| 30 | +np.random.seed(123) |
| 31 | +x = np.random.randn(100) + 5 |
| 32 | + |
| 33 | +# Calculate "standard devation" and "standard error" locations |
| 34 | +sdVal = np.std(x, ddof=1) |
| 35 | +seVal = stats.sem(x) |
| 36 | +sd = np.mean(x) + sdVal*np.r_[-1, 1] |
| 37 | +se = np.mean(x) + seVal*np.r_[-1, 1] |
| 38 | + |
| 39 | +# Set up the plot |
| 40 | +sns.set_style('ticks') |
| 41 | +sns.set_context('poster') |
| 42 | +setFonts() |
| 43 | + |
| 44 | +# Plot the data |
| 45 | +plt.plot(x,'.') |
| 46 | +plt.axhline(np.mean(x), color=0.7*np.ones(3)) |
| 47 | +plt.axhline(sd[0], ls='--') |
| 48 | +plt.axhline(sd[1], ls='--') |
| 49 | + |
| 50 | +# Lines for SEM |
| 51 | +lh = [] |
| 52 | +lh.append( plt.axhline(se[0], ls='--', color='r') ) |
| 53 | +lh.append( plt.axhline(se[1], ls='--', color='r') ) |
| 54 | + |
| 55 | +# make the lines long-dashed |
| 56 | +dashes = [20, 5] # 20 points on, 5 off |
| 57 | +for ii in range(len(lh)): |
| 58 | + lh[ii].set_dashes(dashes) |
| 59 | + |
| 60 | +curAxis = plt.gca() |
| 61 | +curAxis.set_xticklabels( () ) |
| 62 | + |
| 63 | +# Make the arrows |
| 64 | +plt.arrow(10, np.mean(x), 0, sdVal, |
| 65 | + width=0.2, length_includes_head=True, head_length=0.2, head_width=1, color='k') |
| 66 | +plt.arrow(10, np.mean(x), 0, -sdVal, |
| 67 | + width=0.2, length_includes_head=True, head_length=0.2, head_width=1, color='k') |
| 68 | + |
| 69 | +plt.arrow(35, np.mean(x)-4*seVal, 0, 3*seVal, |
| 70 | + width=0.2, length_includes_head=True, head_length=0.1, head_width=1, color='k') |
| 71 | +plt.arrow(35, np.mean(x)+4*seVal, 0, -3*seVal, |
| 72 | + width=0.2, length_includes_head=True, head_length=0.1, head_width=1, color='k') |
| 73 | + |
| 74 | +#plt.text(10, 5.5, '$\pm$ 1SD', family='sans-seriv', fontsize=28) |
| 75 | +#plt.text(35, 5.2, '$\pm$ 1SEM', family='sans-seriv', fontsize=28) |
| 76 | +plt.text(10, 5.5, '$\pm$ 1SD', fontsize=28) |
| 77 | +plt.text(35, 5.2, '$\pm$ 1SEM', fontsize=28) |
| 78 | +plt.annotate('mean', (70,np.mean(x)),xycoords='data', fontsize=28, |
| 79 | + xytext=(75, 5.5), textcoords='data', |
| 80 | + arrowprops=dict(facecolor='black', shrink=0.05)) |
| 81 | + |
| 82 | + |
| 83 | +# Add the text |
| 84 | + |
| 85 | + |
| 86 | +# Save and show |
| 87 | +outFile = ('standardError.png') |
| 88 | +showData(outFile) |
0 commit comments