{"id":865,"date":"2012-04-10T02:51:24","date_gmt":"2012-04-10T02:51:24","guid":{"rendered":"http:\/\/41j.com\/blog\/?p=865"},"modified":"2012-04-10T02:51:24","modified_gmt":"2012-04-10T02:51:24","slug":"simple-histogram-in-pythonmatplotlib-no-display-write-to-png","status":"publish","type":"post","link":"https:\/\/41j.com\/blog\/2012\/04\/simple-histogram-in-pythonmatplotlib-no-display-write-to-png\/","title":{"rendered":"Simple histogram in python,matplotlib (no display, write to png)"},"content":{"rendered":"<p>Reads from a file called p, uses 10000 bins, filters out values < -10000. Sets a range of -10000 to 3500000, max value of 20. \n\n[sourcecode language=\"python\"]\n#!\/usr\/bin\/env python\nimport numpy as np\nimport matplotlib as mpl\nimport matplotlib.mlab as mlab\nmpl.use('Agg')\nimport matplotlib.pyplot as plt\n\ninp = open (&quot;p&quot;,&quot;r&quot;)\n\nx = []\nfor line in inp.readlines():\n  if int(line) &gt; -10000:\n    x.append(int(line))\n\nprint x\n# the histogram of the data\nn, bins, patches = plt.hist(x, 10000, normed=0, facecolor='green')\nprint bins\nprint n\n\n# add a 'best fit' line\n#y = mlab.normpdf( bins, mu, sigma)\n#l = plt.plot(bins, y, 'r--', linewidth=1)\n\nplt.xlabel('Position')\nplt.ylabel('Population')\nplt.title('My data')\n#plt.axis([-10000,3500000, 0, 20])\nplt.grid(True)\n\nplt.savefig('histogram.png')\n[\/sourcecode]\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Reads from a file called p, uses 10000 bins, filters out values < -10000. Sets a range of -10000 to 3500000, max value of 20. [sourcecode language=\"python\"] #!\/usr\/bin\/env python import numpy as np import matplotlib as mpl import matplotlib.mlab as mlab mpl.use('Agg') import matplotlib.pyplot as plt inp = open (&quot;p&quot;,&quot;r&quot;) x = [] for line [&hellip;]\n<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-865","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1RRoU-dX","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/865","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/comments?post=865"}],"version-history":[{"count":1,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/865\/revisions"}],"predecessor-version":[{"id":866,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/865\/revisions\/866"}],"wp:attachment":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/media?parent=865"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/categories?post=865"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/tags?post=865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}