{"id":95,"date":"2018-10-30T17:45:02","date_gmt":"2018-10-30T21:45:02","guid":{"rendered":"http:\/\/sites.nd.edu\/crivaldi\/?p=95"},"modified":"2019-11-05T14:45:54","modified_gmt":"2019-11-05T18:45:54","slug":"plotting-in-python","status":"publish","type":"post","link":"https:\/\/sites.nd.edu\/crivaldi\/2018\/10\/30\/plotting-in-python\/","title":{"rendered":"Plotting in Python"},"content":{"rendered":"<p><em>*Note to all users: As of 07\/14\/2019, all posts have been moved to (and are being updated at <a href=\"https:\/\/crivaldi.github.io\">crivaldi.github.io . <\/a>I don&#8217;t have plans to shut this site down, but I have no idea how long it will be maintained by the university in the future.*<\/em><\/p>\n<h1>Plotting in (mostly) Python*<\/h1>\n<p>*Note to class: some of these may be python 3 &amp; most of what we&#8217;ve done so far has been in Python 2. Copy and paste with caution*<\/p>\n<hr \/>\n<p><a href=\"https:\/\/plotnine.readthedocs.io\/en\/stable\/installation.html\">Installing the PlotNine Package (ggplots for python)<\/a><\/p>\n<h5>Class Specific notes\/announcements &#8211; 11\/1\/18 &#8211; plotting links continued below<\/h5>\n<p>You do not need to have plotnine installed and working correctly to complete exercise 8. There is some example code in the exercise. We&#8217;ll go over this in office hours later today if it would be helpful.<\/p>\n<p>MAC PEOPLE HAVING TROUBLE WITH PLOTNINE INSTALLATION<\/p>\n<p>We have another thing to try for plotnine installation. We think that maybe if you start a fresh conda environment some of the dependency issues we&#8217;ve been having will be solved. Dr. Jones is waiting to see if we can get this working and then will figure out what to do from there.<\/p>\n<p>In a fresh terminal, type<\/p>\n<p>conda activate<\/p>\n<p>Your terminal should process this for a minute and then your prompt should change from something like this: <code>criva$<\/code> to something like this: <code>(base) criva$<\/code><\/p>\n<p>From there, you can try to use conda to install plotnine again: <code>conda install -c conda-forge plotnine<\/code><\/p>\n<p>Now open spyder and try out some of the plotnine commands. You can use the dataset mpg.txt from class (if you don&#8217;t have this dataset, you can <a href=\"https:\/\/forge.scilab.org\/index.php\/p\/rdataset\/source\/tree\/master\/csv\/ggplot2\/mpg.csv\">download it here<\/a>.)<br \/>\n<code>import numpy<br \/>\nimport pandas as pd<br \/>\nfrom plotnine import *<\/code><\/p>\n<p><code>mpg=pd.read_csv(\"mpg.txt\",sep=\"\\t\",header=0<\/code><\/p>\n<p><code>a = ggplot(mpg,aes(x=\"displ\",y=\"cty\"))<br \/>\na+geom_point()+coord_cartesian()<\/code><\/p>\n<p>Let me know what happens &#8211; hopefully this forces a new environment which should fix the dependency nonsense we&#8217;ve been going through.<\/p>\n<p>Some people were having issues with getting numpy re-installed on Wednesday &#8211; here is some code that should work for you. Let me know if this doesn&#8217;t work. If we didn&#8217;t talk about this, ignore it.<\/p>\n<p>Code for numpy installation<\/p>\n<ul>\n<li>Plotting in Pandas (python code): <span class=\"comment-copy\"><code>sudo pip install --upgrade --ignore-installed --install-option '--install-data=\/usr\/local' numpy<\/code><\/span><\/li>\n<\/ul>\n<p>For what it&#8217;s worth, this dependency issue is not something unique to the class. See comic. (https:\/\/xkcd.com\/1987\/)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium\" src=\"https:\/\/imgs.xkcd.com\/comics\/python_environment.png\" width=\"492\" height=\"487\" \/><\/p>\n<p>&nbsp;<\/p>\n<hr \/>\n<h4>Links to plotting tutorials\/resources<\/h4>\n<p><a href=\"https:\/\/lmicke.github.io\/first-ramen-post.html\">https:\/\/lmicke.github.io\/first-ramen-post.html<\/a><\/p>\n<p><a href=\"https:\/\/lmicke.github.io\/second-ramen-post.html#second-ramen-post\">https:\/\/lmicke.github.io\/second-ramen-post.html#second-ramen-post<\/a><\/p>\n<ul>\n<li>Bunch of different types of graphs and the code to make them (Python code):<\/li>\n<\/ul>\n<p><a href=\"https:\/\/python-graph-gallery.com\/\">https:\/\/python-graph-gallery.com\/<\/a><\/p>\n<ul>\n<li>Useful Python libraries:<\/li>\n<\/ul>\n<p><a href=\"https:\/\/blog.modeanalytics.com\/python-data-visualization-libraries\/\">https:\/\/blog.modeanalytics.com\/python-data-visualization-libraries\/<\/a><\/p>\n<ul>\n<li>All python libraries (similar to R-cran)<\/li>\n<\/ul>\n<p><a href=\"https:\/\/pypi.org\/\">https:\/\/pypi.org\/<\/a><\/p>\n<ul>\n<li>Lots of examples of ggplots2 graphs (R code):<\/li>\n<\/ul>\n<p><a href=\"http:\/\/r-statistics.co\/Top50-Ggplot2-Visualizations-MasterList-R-Code.html#Slope%20Chart\">http:\/\/r-statistics.co\/Top50-Ggplot2-Visualizations-MasterList-R-Code.html#Slope%20Chart<\/a><\/p>\n<ul>\n<li>Advanced data visualization ideas and examples (not necessarily tutorials and not exclusive to python)<\/li>\n<\/ul>\n<p><a href=\"http:\/\/sxywu.com\/\">http:\/\/sxywu.com\/<\/a><\/p>\n<ul>\n<li>If you&#8217;re using jupyter notebooks, here are some tips: <a href=\"https:\/\/www.dataquest.io\/blog\/jupyter-notebook-tips-tricks-shortcuts\/\">https:\/\/www.dataquest.io\/blog\/jupyter-notebook-tips-tricks-shortcuts\/<\/a><\/li>\n<\/ul>\n<blockquote class=\"wp-embedded-content\" data-secret=\"NPNuIw1rEC\"><p><a href=\"https:\/\/python-graph-gallery.com\/\"><\/a><\/p><\/blockquote>\n<p><iframe loading=\"lazy\" title=\"&#8220;&#8221; &#8212; The Python Graph Gallery\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" src=\"https:\/\/python-graph-gallery.com\/embed\/#?secret=NPNuIw1rEC\" data-secret=\"NPNuIw1rEC\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>*Note to all users: As of 07\/14\/2019, all posts have been moved to (and are being updated at crivaldi.github.io . I don&#8217;t have plans to shut this site down, but I have no idea how long it will be maintained by the university in the future.* Plotting in (mostly) Python* *Note to class: some of &hellip; <a href=\"https:\/\/sites.nd.edu\/crivaldi\/2018\/10\/30\/plotting-in-python\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Plotting in Python&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2790,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[29879],"tags":[],"class_list":["post-95","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/sites.nd.edu\/crivaldi\/wp-json\/wp\/v2\/posts\/95","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sites.nd.edu\/crivaldi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sites.nd.edu\/crivaldi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sites.nd.edu\/crivaldi\/wp-json\/wp\/v2\/users\/2790"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.nd.edu\/crivaldi\/wp-json\/wp\/v2\/comments?post=95"}],"version-history":[{"count":17,"href":"https:\/\/sites.nd.edu\/crivaldi\/wp-json\/wp\/v2\/posts\/95\/revisions"}],"predecessor-version":[{"id":172,"href":"https:\/\/sites.nd.edu\/crivaldi\/wp-json\/wp\/v2\/posts\/95\/revisions\/172"}],"wp:attachment":[{"href":"https:\/\/sites.nd.edu\/crivaldi\/wp-json\/wp\/v2\/media?parent=95"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sites.nd.edu\/crivaldi\/wp-json\/wp\/v2\/categories?post=95"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sites.nd.edu\/crivaldi\/wp-json\/wp\/v2\/tags?post=95"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}