Created
August 14, 2018 18:21
-
-
Save saschatimme/97aac4e30eb38715be19caea77a6c5b8 to your computer and use it in GitHub Desktop.
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"using Plots" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"4-element Array{Float64,1}:\n", | |
" 1.0\n", | |
" 3.0\n", | |
" 5.0\n", | |
" 7.0" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"\"\"\"\n", | |
" makebins(centers)\n", | |
"\n", | |
"Creates the bins such that the `length(centers)` many bins are centered around `centers`.\n", | |
"Assume that `centers` are equally spaced.\n", | |
"\"\"\"\n", | |
"function makebins(centers)\n", | |
" # make from [2, 4, 6] -> [1, 3, 5, 7]\n", | |
" [centers[1:end-1]-diff(centers) .* 0.5; centers[end-1:end]+diff(centers[end-2:end]).*0.5]\n", | |
"end\n", | |
"makebins([2, 4, 6])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 16, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/svg+xml": [ | |
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n", | |
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"600\" height=\"400\" viewBox=\"0 0 600 400\">\n", | |
"<defs>\n", | |
" <clipPath id=\"clip5000\">\n", | |
" <rect x=\"0\" y=\"0\" width=\"600\" height=\"400\"/>\n", | |
" </clipPath>\n", | |
"</defs>\n", | |
"<polygon clip-path=\"url(#clip5000)\" points=\"\n", | |
"0,400 600,400 600,0 0,0 \n", | |
" \" fill=\"#ffffff\" fill-opacity=\"1\"/>\n", | |
"<defs>\n", | |
" <clipPath id=\"clip5001\">\n", | |
" <rect x=\"120\" y=\"0\" width=\"421\" height=\"400\"/>\n", | |
" </clipPath>\n", | |
"</defs>\n", | |
"<polygon clip-path=\"url(#clip5000)\" points=\"\n", | |
"59.4418,375.869 580.315,375.869 580.315,11.811 59.4418,11.811 \n", | |
" \" fill=\"#ffffff\" fill-opacity=\"1\"/>\n", | |
"<defs>\n", | |
" <clipPath id=\"clip5002\">\n", | |
" <rect x=\"59\" y=\"11\" width=\"522\" height=\"365\"/>\n", | |
" </clipPath>\n", | |
"</defs>\n", | |
"<polyline clip-path=\"url(#clip5002)\" style=\"stroke:#000000; stroke-width:0.5; stroke-opacity:0.1; fill:none\" points=\"\n", | |
" 121.203,375.869 121.203,11.811 \n", | |
" \"/>\n", | |
"<polyline clip-path=\"url(#clip5002)\" style=\"stroke:#000000; stroke-width:0.5; stroke-opacity:0.1; fill:none\" points=\"\n", | |
" 187.428,375.869 187.428,11.811 \n", | |
" \"/>\n", | |
"<polyline clip-path=\"url(#clip5002)\" style=\"stroke:#000000; stroke-width:0.5; stroke-opacity:0.1; fill:none\" points=\"\n", | |
" 253.653,375.869 253.653,11.811 \n", | |
" \"/>\n", | |
"<polyline clip-path=\"url(#clip5002)\" style=\"stroke:#000000; stroke-width:0.5; stroke-opacity:0.1; fill:none\" points=\"\n", | |
" 319.878,375.869 319.878,11.811 \n", | |
" \"/>\n", | |
"<polyline clip-path=\"url(#clip5002)\" style=\"stroke:#000000; stroke-width:0.5; stroke-opacity:0.1; fill:none\" points=\"\n", | |
" 386.103,375.869 386.103,11.811 \n", | |
" \"/>\n", | |
"<polyline clip-path=\"url(#clip5002)\" style=\"stroke:#000000; stroke-width:0.5; stroke-opacity:0.1; fill:none\" points=\"\n", | |
" 452.328,375.869 452.328,11.811 \n", | |
" \"/>\n", | |
"<polyline clip-path=\"url(#clip5002)\" style=\"stroke:#000000; stroke-width:0.5; stroke-opacity:0.1; fill:none\" points=\"\n", | |
" 518.553,375.869 518.553,11.811 \n", | |
" \"/>\n", | |
"<polyline clip-path=\"url(#clip5002)\" style=\"stroke:#000000; stroke-width:0.5; stroke-opacity:0.1; fill:none\" points=\"\n", | |
" 59.4418,365.565 580.315,365.565 \n", | |
" \"/>\n", | |
"<polyline clip-path=\"url(#clip5002)\" style=\"stroke:#000000; stroke-width:0.5; stroke-opacity:0.1; fill:none\" points=\"\n", | |
" 59.4418,273.978 580.315,273.978 \n", | |
" \"/>\n", | |
"<polyline clip-path=\"url(#clip5002)\" style=\"stroke:#000000; stroke-width:0.5; stroke-opacity:0.1; fill:none\" points=\"\n", | |
" 59.4418,182.391 580.315,182.391 \n", | |
" \"/>\n", | |
"<polyline clip-path=\"url(#clip5002)\" style=\"stroke:#000000; stroke-width:0.5; stroke-opacity:0.1; fill:none\" points=\"\n", | |
" 59.4418,90.8047 580.315,90.8047 \n", | |
" \"/>\n", | |
"<polyline clip-path=\"url(#clip5000)\" style=\"stroke:#000000; stroke-width:1; stroke-opacity:1; fill:none\" points=\"\n", | |
" 59.4418,375.869 580.315,375.869 \n", | |
" \"/>\n", | |
"<polyline clip-path=\"url(#clip5000)\" style=\"stroke:#000000; stroke-width:1; stroke-opacity:1; fill:none\" points=\"\n", | |
" 59.4418,375.869 59.4418,11.811 \n", | |
" \"/>\n", | |
"<polyline clip-path=\"url(#clip5000)\" style=\"stroke:#000000; stroke-width:1; stroke-opacity:1; fill:none\" points=\"\n", | |
" 121.203,375.869 121.203,370.408 \n", | |
" \"/>\n", | |
"<polyline clip-path=\"url(#clip5000)\" style=\"stroke:#000000; stroke-width:1; stroke-opacity:1; fill:none\" points=\"\n", | |
" 187.428,375.869 187.428,370.408 \n", | |
" \"/>\n", | |
"<polyline clip-path=\"url(#clip5000)\" style=\"stroke:#000000; stroke-width:1; stroke-opacity:1; fill:none\" points=\"\n", | |
" 253.653,375.869 253.653,370.408 \n", | |
" \"/>\n", | |
"<polyline clip-path=\"url(#clip5000)\" style=\"stroke:#000000; stroke-width:1; stroke-opacity:1; fill:none\" points=\"\n", | |
" 319.878,375.869 319.878,370.408 \n", | |
" \"/>\n", | |
"<polyline clip-path=\"url(#clip5000)\" style=\"stroke:#000000; stroke-width:1; stroke-opacity:1; fill:none\" points=\"\n", | |
" 386.103,375.869 386.103,370.408 \n", | |
" \"/>\n", | |
"<polyline clip-path=\"url(#clip5000)\" style=\"stroke:#000000; stroke-width:1; stroke-opacity:1; fill:none\" points=\"\n", | |
" 452.328,375.869 452.328,370.408 \n", | |
" \"/>\n", | |
"<polyline clip-path=\"url(#clip5000)\" style=\"stroke:#000000; stroke-width:1; stroke-opacity:1; fill:none\" points=\"\n", | |
" 518.553,375.869 518.553,370.408 \n", | |
" \"/>\n", | |
"<polyline clip-path=\"url(#clip5000)\" style=\"stroke:#000000; stroke-width:1; stroke-opacity:1; fill:none\" points=\"\n", | |
" 59.4418,365.565 67.2549,365.565 \n", | |
" \"/>\n", | |
"<polyline clip-path=\"url(#clip5000)\" style=\"stroke:#000000; stroke-width:1; stroke-opacity:1; fill:none\" points=\"\n", | |
" 59.4418,273.978 67.2549,273.978 \n", | |
" \"/>\n", | |
"<polyline clip-path=\"url(#clip5000)\" style=\"stroke:#000000; stroke-width:1; stroke-opacity:1; fill:none\" points=\"\n", | |
" 59.4418,182.391 67.2549,182.391 \n", | |
" \"/>\n", | |
"<polyline clip-path=\"url(#clip5000)\" style=\"stroke:#000000; stroke-width:1; stroke-opacity:1; fill:none\" points=\"\n", | |
" 59.4418,90.8047 67.2549,90.8047 \n", | |
" \"/>\n", | |
"<g clip-path=\"url(#clip5000)\">\n", | |
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:middle;\" transform=\"rotate(0, 121.203, 389.669)\" x=\"121.203\" y=\"389.669\">4</text>\n", | |
"</g>\n", | |
"<g clip-path=\"url(#clip5000)\">\n", | |
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:middle;\" transform=\"rotate(0, 187.428, 389.669)\" x=\"187.428\" y=\"389.669\">6</text>\n", | |
"</g>\n", | |
"<g clip-path=\"url(#clip5000)\">\n", | |
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:middle;\" transform=\"rotate(0, 253.653, 389.669)\" x=\"253.653\" y=\"389.669\">8</text>\n", | |
"</g>\n", | |
"<g clip-path=\"url(#clip5000)\">\n", | |
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:middle;\" transform=\"rotate(0, 319.878, 389.669)\" x=\"319.878\" y=\"389.669\">10</text>\n", | |
"</g>\n", | |
"<g clip-path=\"url(#clip5000)\">\n", | |
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:middle;\" transform=\"rotate(0, 386.103, 389.669)\" x=\"386.103\" y=\"389.669\">12</text>\n", | |
"</g>\n", | |
"<g clip-path=\"url(#clip5000)\">\n", | |
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:middle;\" transform=\"rotate(0, 452.328, 389.669)\" x=\"452.328\" y=\"389.669\">14</text>\n", | |
"</g>\n", | |
"<g clip-path=\"url(#clip5000)\">\n", | |
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:middle;\" transform=\"rotate(0, 518.553, 389.669)\" x=\"518.553\" y=\"389.669\">16</text>\n", | |
"</g>\n", | |
"<g clip-path=\"url(#clip5000)\">\n", | |
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:end;\" transform=\"rotate(0, 53.4418, 370.065)\" x=\"53.4418\" y=\"370.065\">0</text>\n", | |
"</g>\n", | |
"<g clip-path=\"url(#clip5000)\">\n", | |
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:end;\" transform=\"rotate(0, 53.4418, 278.478)\" x=\"53.4418\" y=\"278.478\">100</text>\n", | |
"</g>\n", | |
"<g clip-path=\"url(#clip5000)\">\n", | |
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:end;\" transform=\"rotate(0, 53.4418, 186.891)\" x=\"53.4418\" y=\"186.891\">200</text>\n", | |
"</g>\n", | |
"<g clip-path=\"url(#clip5000)\">\n", | |
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:end;\" transform=\"rotate(0, 53.4418, 95.3047)\" x=\"53.4418\" y=\"95.3047\">300</text>\n", | |
"</g>\n", | |
"<g clip-path=\"url(#clip5000)\">\n", | |
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:16; text-anchor:middle;\" transform=\"rotate(-90, 14.4, 193.84)\" x=\"14.4\" y=\"193.84\">Cool sample values</text>\n", | |
"</g>\n", | |
"<polygon clip-path=\"url(#clip5002)\" points=\"\n", | |
"88.0908,361.902 88.0908,365.565 154.316,365.565 154.316,361.902 88.0908,361.902 88.0908,361.902 \n", | |
" \" fill=\"#009af9\" fill-opacity=\"1\"/>\n", | |
"<polyline clip-path=\"url(#clip5002)\" style=\"stroke:#000000; stroke-width:1; stroke-opacity:1; fill:none\" points=\"\n", | |
" 88.0908,361.902 88.0908,365.565 154.316,365.565 154.316,361.902 88.0908,361.902 \n", | |
" \"/>\n", | |
"<polygon clip-path=\"url(#clip5002)\" points=\"\n", | |
"154.316,321.603 154.316,365.565 220.541,365.565 220.541,321.603 154.316,321.603 154.316,321.603 \n", | |
" \" fill=\"#009af9\" fill-opacity=\"1\"/>\n", | |
"<polyline clip-path=\"url(#clip5002)\" style=\"stroke:#000000; stroke-width:1; stroke-opacity:1; fill:none\" points=\"\n", | |
" 154.316,321.603 154.316,365.565 220.541,365.565 220.541,321.603 154.316,321.603 \n", | |
" \"/>\n", | |
"<polygon clip-path=\"url(#clip5002)\" points=\"\n", | |
"220.541,145.757 220.541,365.565 286.766,365.565 286.766,145.757 220.541,145.757 220.541,145.757 \n", | |
" \" fill=\"#009af9\" fill-opacity=\"1\"/>\n", | |
"<polyline clip-path=\"url(#clip5002)\" style=\"stroke:#000000; stroke-width:1; stroke-opacity:1; fill:none\" points=\"\n", | |
" 220.541,145.757 220.541,365.565 286.766,365.565 286.766,145.757 220.541,145.757 \n", | |
" \"/>\n", | |
"<polygon clip-path=\"url(#clip5002)\" points=\"\n", | |
"286.766,22.1145 286.766,365.565 352.991,365.565 352.991,22.1145 286.766,22.1145 286.766,22.1145 \n", | |
" \" fill=\"#009af9\" fill-opacity=\"1\"/>\n", | |
"<polyline clip-path=\"url(#clip5002)\" style=\"stroke:#000000; stroke-width:1; stroke-opacity:1; fill:none\" points=\"\n", | |
" 286.766,22.1145 286.766,365.565 352.991,365.565 352.991,22.1145 286.766,22.1145 \n", | |
" \"/>\n", | |
"<polygon clip-path=\"url(#clip5002)\" points=\"\n", | |
"352.991,130.187 352.991,365.565 419.216,365.565 419.216,130.187 352.991,130.187 352.991,130.187 \n", | |
" \" fill=\"#009af9\" fill-opacity=\"1\"/>\n", | |
"<polyline clip-path=\"url(#clip5002)\" style=\"stroke:#000000; stroke-width:1; stroke-opacity:1; fill:none\" points=\"\n", | |
" 352.991,130.187 352.991,365.565 419.216,365.565 419.216,130.187 352.991,130.187 \n", | |
" \"/>\n", | |
"<polygon clip-path=\"url(#clip5002)\" points=\"\n", | |
"419.216,302.37 419.216,365.565 485.441,365.565 485.441,302.37 419.216,302.37 419.216,302.37 \n", | |
" \" fill=\"#009af9\" fill-opacity=\"1\"/>\n", | |
"<polyline clip-path=\"url(#clip5002)\" style=\"stroke:#000000; stroke-width:1; stroke-opacity:1; fill:none\" points=\"\n", | |
" 419.216,302.37 419.216,365.565 485.441,365.565 485.441,302.37 419.216,302.37 \n", | |
" \"/>\n", | |
"<polygon clip-path=\"url(#clip5002)\" points=\"\n", | |
"485.441,359.154 485.441,365.565 551.666,365.565 551.666,359.154 485.441,359.154 485.441,359.154 \n", | |
" \" fill=\"#009af9\" fill-opacity=\"1\"/>\n", | |
"<polyline clip-path=\"url(#clip5002)\" style=\"stroke:#000000; stroke-width:1; stroke-opacity:1; fill:none\" points=\"\n", | |
" 485.441,359.154 485.441,365.565 551.666,365.565 551.666,359.154 485.441,359.154 \n", | |
" \"/>\n", | |
"<polygon clip-path=\"url(#clip5000)\" points=\"\n", | |
"445.481,62.931 562.315,62.931 562.315,32.691 445.481,32.691 \n", | |
" \" fill=\"#ffffff\" fill-opacity=\"1\"/>\n", | |
"<polyline clip-path=\"url(#clip5000)\" style=\"stroke:#000000; stroke-width:1; stroke-opacity:1; fill:none\" points=\"\n", | |
" 445.481,62.931 562.315,62.931 562.315,32.691 445.481,32.691 445.481,62.931 \n", | |
" \"/>\n", | |
"<polygon clip-path=\"url(#clip5000)\" points=\"\n", | |
"451.481,53.859 487.481,53.859 487.481,41.763 451.481,41.763 451.481,53.859 \n", | |
" \" fill=\"#009af9\" fill-opacity=\"1\"/>\n", | |
"<polyline clip-path=\"url(#clip5000)\" style=\"stroke:#000000; stroke-width:1; stroke-opacity:1; fill:none\" points=\"\n", | |
" 451.481,53.859 487.481,53.859 487.481,41.763 451.481,41.763 451.481,53.859 \n", | |
" \"/>\n", | |
"<g clip-path=\"url(#clip5000)\">\n", | |
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:12; text-anchor:start;\" transform=\"rotate(0, 493.481, 52.311)\" x=\"493.481\" y=\"52.311\">MY DATA!</text>\n", | |
"</g>\n", | |
"</svg>\n" | |
] | |
}, | |
"execution_count": 16, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"centers = [4, 6, 8, 10, 12, 14, 16]\n", | |
"histogram(randn(1000) .* 2 .+ 10,\n", | |
" bins=makebins(centers),\n", | |
" ylabel=\"Cool sample values\",\n", | |
" label=\"MY DATA!\",\n", | |
" xticks=centers,\n", | |
" #bar_width = 1\n", | |
")" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Julia 0.6.1", | |
"language": "julia", | |
"name": "julia-0.6" | |
}, | |
"language_info": { | |
"file_extension": ".jl", | |
"mimetype": "application/julia", | |
"name": "julia", | |
"version": "0.6.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment