PageRenderTime 396ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/fetch_fasta_description_for_blasthit/pymodules/python2.7/lib/python/statsmodels-0.5.0-py2.7-linux-x86_64.egg/statsmodels/examples/example_enhanced_boxplots.py

https://gitlab.com/pooja043/Globus_Docker_3
Python | 98 lines | 65 code | 26 blank | 7 comment | 3 complexity | 8d8f47db780a5a27dd167defec6193e7 MD5 | raw file
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import statsmodels.api as sm
  4. # Necessary to make horizontal axis labels fit
  5. plt.rcParams['figure.subplot.bottom'] = 0.23
  6. data = sm.datasets.anes96.load_pandas()
  7. party_ID = np.arange(7)
  8. labels = ["Strong Democrat", "Weak Democrat", "Independent-Democrat",
  9. "Independent-Independent", "Independent-Republican",
  10. "Weak Republican", "Strong Republican"]
  11. # Group age by party ID.
  12. age = [data.exog['age'][data.endog == id] for id in party_ID]
  13. # Create a violin plot.
  14. fig = plt.figure()
  15. ax = fig.add_subplot(111)
  16. sm.graphics.violinplot(age, ax=ax, labels=labels,
  17. plot_opts={'cutoff_val':5, 'cutoff_type':'abs',
  18. 'label_fontsize':'small',
  19. 'label_rotation':30})
  20. ax.set_xlabel("Party identification of respondent.")
  21. ax.set_ylabel("Age")
  22. ax.set_title("US national election '96 - Age & Party Identification")
  23. # Create a bean plot.
  24. fig2 = plt.figure()
  25. ax = fig2.add_subplot(111)
  26. sm.graphics.beanplot(age, ax=ax, labels=labels,
  27. plot_opts={'cutoff_val':5, 'cutoff_type':'abs',
  28. 'label_fontsize':'small',
  29. 'label_rotation':30})
  30. ax.set_xlabel("Party identification of respondent.")
  31. ax.set_ylabel("Age")
  32. ax.set_title("US national election '96 - Age & Party Identification")
  33. # Create a jitter plot.
  34. fig3 = plt.figure()
  35. ax = fig3.add_subplot(111)
  36. plot_opts={'cutoff_val':5, 'cutoff_type':'abs', 'label_fontsize':'small',
  37. 'label_rotation':30, 'violin_fc':(0.8, 0.8, 0.8),
  38. 'jitter_marker':'.', 'jitter_marker_size':3, 'bean_color':'#FF6F00',
  39. 'bean_mean_color':'#009D91'}
  40. sm.graphics.beanplot(age, ax=ax, labels=labels, jitter=True,
  41. plot_opts=plot_opts)
  42. ax.set_xlabel("Party identification of respondent.")
  43. ax.set_ylabel("Age")
  44. ax.set_title("US national election '96 - Age & Party Identification")
  45. # Create an asymmetrical jitter plot.
  46. ix = data.exog['income'] < 16 # incomes < $30k
  47. age = data.exog['age'][ix]
  48. endog = data.endog[ix]
  49. age_lower_income = [age[endog == id] for id in party_ID]
  50. ix = data.exog['income'] >= 20 # incomes > $50k
  51. age = data.exog['age'][ix]
  52. endog = data.endog[ix]
  53. age_higher_income = [age[endog == id] for id in party_ID]
  54. fig = plt.figure()
  55. ax = fig.add_subplot(111)
  56. plot_opts['violin_fc'] = (0.5, 0.5, 0.5)
  57. plot_opts['bean_show_mean'] = False
  58. plot_opts['bean_show_median'] = False
  59. plot_opts['bean_legend_text'] = 'Income < \$30k'
  60. plot_opts['cutoff_val'] = 10
  61. sm.graphics.beanplot(age_lower_income, ax=ax, labels=labels, side='left',
  62. jitter=True, plot_opts=plot_opts)
  63. plot_opts['violin_fc'] = (0.7, 0.7, 0.7)
  64. plot_opts['bean_color'] = '#009D91'
  65. plot_opts['bean_legend_text'] = 'Income > \$50k'
  66. sm.graphics.beanplot(age_higher_income, ax=ax, labels=labels, side='right',
  67. jitter=True, plot_opts=plot_opts)
  68. ax.set_xlabel("Party identification of respondent.")
  69. ax.set_ylabel("Age")
  70. ax.set_title("US national election '96 - Age & Party Identification")
  71. # Show all plots.
  72. plt.show()