{"id":11631,"date":"2017-08-02T17:41:51","date_gmt":"2017-08-02T08:41:51","guid":{"rendered":"http:\/\/sitest.jp\/blog\/?p=11631"},"modified":"2017-08-02T17:41:51","modified_gmt":"2017-08-02T08:41:51","slug":"python-%e3%81%a8-matplotlib-%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e6%89%8b%e8%bb%bd%e3%81%ab%e7%b5%b1%e8%a8%88%e3%83%87%e3%83%bc%e3%82%bf%e3%82%92%e5%8f%af%e8%a6%96%e5%8c%96%e3%81%97%e3%81%a6%e3%81%bf","status":"publish","type":"post","link":"https:\/\/sitest.jp\/blog\/?p=11631","title":{"rendered":"Python \u3068 matplotlib \u3092\u4f7f\u3063\u3066\u624b\u8efd\u306b\u7d71\u8a08\u30c7\u30fc\u30bf\u3092\u53ef\u8996\u5316\u3057\u3066\u307f\u3088\u3046\uff01"},"content":{"rendered":"<p>\u4ee5\u524d\u3001\u4e0b\u8a18\u306e\u8a18\u4e8b\u3067 R \u8a00\u8a9e\u3092\u4f7f\u3063\u3066\u7d71\u8a08\u30c7\u30fc\u30bf\u3092\u53ef\u8996\u5316\u3059\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002<br \/>\n\u300c <a target=\"_blank\" href=\"http:\/\/sitest.jp\/blog\/?p=9221\">R\u8a00\u8a9e\u3067\u7d71\u8a08\u30c7\u30fc\u30bf\u3092\u53ef\u8996\u5316\u3057\u3088\u3046\uff01R\u8a00\u8a9e\u30b0\u30e9\u30d5\u5165\u9580<\/a> \u300d<\/p>\n<p>R \u8a00\u8a9e\u3067\u3082\u624b\u8efd\u306b\u30c7\u30fc\u30bf\u306e\u53ef\u8996\u5316\u3092\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u3059\u304c\u3001<br \/>\n\u5b9f\u306f Python \u3067\u3082\u7c21\u5358\u306b\u30c7\u30fc\u30bf\u306e\u53ef\u8996\u5316\u3092\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306f matplotlib \u3068\u3044\u3046\u30b0\u30e9\u30d5\u63cf\u753b\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3057\u3066\u3001<br \/>\nPython \u3067\u30c7\u30fc\u30bf\u3092\u53ef\u8996\u5316\u3059\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\uff01<\/p>\n<p><!--more--><\/p>\n<div class=\"frame_headding\">\n<h3 style=\"text-align: left;\">\u4e8b\u524d\u6e96\u5099<\/h3>\n<\/div>\n<p>\u307e\u305a\u3001 <a target=\"_blank\" rel=\"nofollow\" href=\"http:\/\/matplotlib.org\/\">matplotlib<\/a> \u3068\u306f\u3001 Python \u3067\u30b0\u30e9\u30d5\u3092\u63cf\u753b\u3059\u308b\u6642\u306b\u3088\u304f\u4f7f\u7528\u3055\u308c\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002<br \/>\n\u3069\u306e\u3088\u3046\u306a\u30b0\u30e9\u30d5\u3092\u63cf\u753b\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u308b\u306e\u304b\u306f<a target=\"_blank\" rel=\"nofollow\" href=\"http:\/\/matplotlib.org\/gallery.html\">\u30ae\u30e3\u30e9\u30ea\u30fc<\/a>\u304b\u3089\u898b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n\u30b0\u30e9\u30d5\u63cf\u753b\u306b\u306f <a target=\"_blank\" rel=\"nofollow\" href=\"http:\/\/scikit-learn.org\/stable\/index.html\">scikit-learn<\/a> \u306b\u4ed8\u5c5e\u3057\u3066\u3044\u308b\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>\u4eca\u56de\u4f7f\u7528\u3059\u308b\u74b0\u5883\u3068\u3057\u3066\u306f\u3001<\/p>\n<ul>\n<li>Python 2.7<\/li>\n<li>matplotlib 2.0.2<\/li>\n<li>numpy 1.13.0<\/li>\n<li>scipy 0.19.1<\/li>\n<li>scikit-learn 0.18.2<\/li>\n<\/ul>\n<p>\u3092\u4f7f\u7528\u3057\u3066\u9032\u3081\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u6700\u521d\u306b\u5fc5\u8981\u3068\u306a\u308b\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><code>$ pip install numpy scipy scikit-learn matplotlib<\/code><\/pre>\n<p>\u4f5c\u6210\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u306e\u5148\u982d\u3067\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u8aad\u307f\u8fbc\u307f\u307e\u3059\u3002<\/p>\n<pre><code class=\"python\">from sklearn import datasets\nfrom matplotlib import pyplot as plt\nimport numpy as np\n<\/code><\/pre>\n<p>\u3053\u308c\u3067\u6e96\u5099\u5b8c\u4e86\u3067\u3059\u3001\u305d\u308c\u3067\u306f\u30b0\u30e9\u30d5\u306e\u63cf\u753b\u3092\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\uff01<\/p>\n<div class=\"frame_headding\">\n<h3 style=\"text-align: left;\">\u30b0\u30e9\u30d5\u3092\u63cf\u753b\u3057\u3066\u307f\u3088\u3046<\/h3>\n<\/div>\n<h4 style=\"border-bottom: solid 4px #73bc9b; margin-bottom: 30px;\">\u7dda\u30b0\u30e9\u30d5<\/h4>\n<p>Sin \u6ce2\u3068 Cos \u6ce2\u3092\u639b\u3051\u5408\u308f\u305b\u305f\u7dda\u30b0\u30e9\u30d5\u3092\u4f5c\u6210\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br \/>\nNumpy \u3092\u4f7f\u3048\u3070\u3001\u5bfe\u8c61\u533a\u9593\u306e\u6570\u5b66\u95a2\u6570\u6ce2\u5f62\u3092\u7c21\u5358\u306b\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<br \/>\n\u30b0\u30e9\u30d5\u306e\u639b\u3051\u5408\u308f\u305b\u306f <code>plt.plot<\/code> \u95a2\u6570\u3092\u30b0\u30e9\u30d5\u306e\u6570\u3060\u3051\u5b9f\u884c\u3059\u308b\u3060\u3051\u3067\u3059\u3002<br \/>\n\u6700\u5f8c\u306b <code>plot.show()<\/code> \u95a2\u6570\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u3067\u30b0\u30e9\u30d5\u63cf\u753b\u304c\u884c\u308f\u308c\u307e\u3059\u3002<\/p>\n<pre><code class=\"python\">def line():\n    x = np.arange(-np.pi, np.pi, 0.1)\n    sin_y = np.sin(x)\n    cos_y = np.cos(x)\n    plt.plot(x, sin_y)\n    plt.plot(x, cos_y)\n    plt.show()\n<\/code><\/pre>\n<p><!-- img --><br \/>\n<a href=\"https:\/\/storage.googleapis.com\/sitest-wp\/blog\/wp-content\/uploads\/2017\/07\/line.png\"><img loading=\"lazy\" src=\"https:\/\/storage.googleapis.com\/sitest-wp\/blog\/wp-content\/uploads\/2017\/07\/line.png\" alt=\"\" width=\"896\" height=\"480\" class=\"alignnone size-full wp-image-11715\" \/><\/a><\/p>\n<h4 style=\"border-bottom: solid 4px #73bc9b; margin-bottom: 30px;\">\u5186\u30b0\u30e9\u30d5<\/h4>\n<p>\u5186\u30b0\u30e9\u30d5\u306f <code>plt.pie<\/code> \u95a2\u6570\u3067\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n20\u304b\u308970\u307e\u3067\u306e\u30e9\u30f3\u30c0\u30e0\u306a\u6570\u5024\u30927\u500b\u4f5c\u6210\u3057\u3001<br \/>\n\u305d\u308c\u3092\u5186\u30b0\u30e9\u30d5\u306b\u843d\u3068\u3057\u8fbc\u3093\u3067\u3044\u307e\u3059\u3002<br \/>\n\u74b0\u5883\u306b\u3088\u3063\u3066\u306f <code>plt.pie<\/code> \u3060\u3051\u3060\u3068\u6f70\u308c\u305f\u6955\u5186\u5f62\u3068\u306a\u3063\u3066\u3057\u307e\u3046\u305f\u3081\u3001<br \/>\n<code>plt.axis('equal')<\/code> \u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u554f\u984c\u306a\u304f\u8868\u793a\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><code class=\"python\">def pie():\n    sizes = np.random.rand(7) * 70 + 20\n    plt.pie(sizes, autopct='%1.1f%%', startangle=90)\n    plt.axis('equal')\n    plt.show()\n<\/code><\/pre>\n<p><!-- img --><br \/>\n<a href=\"https:\/\/storage.googleapis.com\/sitest-wp\/blog\/wp-content\/uploads\/2017\/07\/pie.png\"><img loading=\"lazy\" src=\"https:\/\/storage.googleapis.com\/sitest-wp\/blog\/wp-content\/uploads\/2017\/07\/pie.png\" alt=\"\" width=\"640\" height=\"480\" class=\"alignnone size-full wp-image-11716\" \/><\/a><\/p>\n<h4 style=\"border-bottom: solid 4px #73bc9b; margin-bottom: 30px;\">\u30d2\u30b9\u30c8\u30b0\u30e9\u30e0<\/h4>\n<p>\u30d2\u30b9\u30c8\u30b0\u30e9\u30e0\u306f <code>plt.hist<\/code> \u95a2\u6570\u3067\u63cf\u753b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n\u5e73\u5747\u304c20\u3067\u6a19\u6e96\u504f\u5dee\u304c10\u306e\u6b63\u898f\u5206\u5e03\u3068\u3001<br \/>\n\u5e73\u5747\u304c40\u3067\u6a19\u6e96\u504f\u5dee\u304c10\u306e\u6b63\u898f\u5206\u5e03\u3092\u91cd\u306d\u3066\u63cf\u753b\u3057\u307e\u3057\u305f\u3002<br \/>\n<code>plt.hist<\/code> \u95a2\u6570\u306e\u5f15\u6570\u306b <code>alpha<\/code> \u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u900f\u660e\u5ea6\u3092\u5909\u3048\u305f\u308a\u3001<br \/>\n<code>plt.legend<\/code> \u95a2\u6570\u3067\u51e1\u4f8b\u3092\u8868\u793a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre><code class=\"python\">def hist():\n    x = np.random.normal(20, 10, 100)\n    y = np.random.normal(40, 10, 100)\n    plt.hist(x, label = \"x\", bins=20, alpha=0.5)\n    plt.hist(y, label = \"y\", bins=20, alpha=0.5)\n    plt.legend()\n    plt.show()\n<\/code><\/pre>\n<p><!-- img --><br \/>\n<a href=\"https:\/\/storage.googleapis.com\/sitest-wp\/blog\/wp-content\/uploads\/2017\/07\/hist.png\"><img loading=\"lazy\" src=\"https:\/\/storage.googleapis.com\/sitest-wp\/blog\/wp-content\/uploads\/2017\/07\/hist.png\" alt=\"\" width=\"640\" height=\"480\" class=\"alignnone size-full wp-image-11717\" \/><\/a><\/p>\n<h4 style=\"border-bottom: solid 4px #73bc9b; margin-bottom: 30px;\">\u6563\u5e03\u56f3<\/h4>\n<p>\u6700\u5f8c\u306b <code>scikit-lean<\/code> \u306b\u4ed8\u5c5e\u3057\u3066\u3044\u308b <code>iris<\/code> \u306e\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u4f7f\u7528\u3057\u3066<br \/>\n\u6563\u5e03\u56f3\u3092\u63cf\u753b\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br \/>\n\u83d6\u84b2\u306e\u843c\u7247\u306e\u9577\u3055\u3068\u5e45\u3092\u54c1\u7a2e\u3054\u3068\u306b\u6563\u5e03\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u6563\u5e03\u56f3\u306f <code>plt.scatter<\/code> \u95a2\u6570\u3067\u5f15\u6570\u306b x \u8ef8\u3001 y \u8ef8\u306e\u30c7\u30fc\u30bf\u3068\u3001<br \/>\n\u30de\u30fc\u30ab\u30fc\u306e\u7a2e\u985e\u3001\u8272\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre><code class=\"python\">def scatter():\n    iris = datasets.load_iris()\n    features = iris.data\n    feature_names = iris.feature_names\n    targets = iris.target\n\n    for t, marker, color in zip(range(3), '>ox', 'rgb'):\n        plt.scatter(\n            features[targets == t, 0],\n            features[targets == t, 1],\n            marker=marker,\n            c=color\n        )\n        plt.xlabel(feature_names[0])\n        plt.ylabel(feature_names[1])\n        plt.autoscale()\n        plt.grid()\n    plt.show()\n<\/code><\/pre>\n<p><!-- img --><br \/>\n<a href=\"https:\/\/storage.googleapis.com\/sitest-wp\/blog\/wp-content\/uploads\/2017\/07\/scatter.png\"><img loading=\"lazy\" src=\"https:\/\/storage.googleapis.com\/sitest-wp\/blog\/wp-content\/uploads\/2017\/07\/scatter.png\" alt=\"\" width=\"640\" height=\"480\" class=\"alignnone size-full wp-image-11718\" \/><\/a><\/p>\n<div class=\"frame_headding\">\n<h3 style=\"text-align: left;\">\u307e\u3068\u3081<\/h3>\n<\/div>\n<p>Python \u306f R \u8a00\u8a9e\u307b\u3069\u624b\u8efd\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u304c\u3001<br \/>\nR \u8a00\u8a9e\u3067\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u3092\u4f5c\u6210\u3057\u3066 Python \u3067\u30d7\u30ed\u30c0\u30af\u30c8\u306b\u7d44\u307f\u8fbc\u3080\u3068\u3044\u3046<br \/>\n\u958b\u767a\u30b5\u30a4\u30af\u30eb\u3092\u56de\u3059\u3053\u3068\u304c\u3067\u304d\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u4eca\u5f8c\u3082 R \u8a00\u8a9e\u3068 Python \u4e21\u65b9\u306e\u89b3\u70b9\u304b\u3089\u307f\u305f\u30c7\u30fc\u30bf\u51e6\u7406\u3092\u8a18\u4e8b\u306b\u3057\u3066\u3044\u304d\u307e\u3059\u306e\u3067\u3001<br \/>\n\u304a\u697d\u3057\u307f\u306b\u304a\u5f85\u3061\u4e0b\u3055\u3044\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee5\u524d\u3001\u4e0b\u8a18\u306e\u8a18\u4e8b\u3067 R \u8a00\u8a9e\u3092\u4f7f\u3063\u3066\u7d71\u8a08\u30c7\u30fc\u30bf\u3092\u53ef\u8996\u5316\u3059\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002 \u300c R\u8a00\u8a9e\u3067\u7d71\u8a08\u30c7\u30fc\u30bf\u3092\u53ef\u8996\u5316\u3057\u3088\u3046\uff01R\u8a00\u8a9e\u30b0\u30e9\u30d5\u5165\u9580 \u300d R \u8a00\u8a9e\u3067\u3082\u624b\u8efd\u306b\u30c7\u30fc\u30bf\u306e\u53ef\u8996\u5316\u3092\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u3059\u304c\u3001 \u5b9f\u306f Python \u3067\u3082\u7c21\u5358\u306b\u30c7\u30fc\u30bf\u306e\u53ef\u8996\u5316\u3092\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002 \u4eca\u56de\u306f matplotlib \u3068\u3044\u3046\u30b0\u30e9\u30d5\u63cf\u753b\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3057\u3066\u3001 Python \u3067\u30c7\u30fc\u30bf\u3092\u53ef\u8996\u5316\u3059\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\uff01<\/p>\n","protected":false},"author":1,"featured_media":11731,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[27],"tags":[],"acf":false,"_links":{"self":[{"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/posts\/11631"}],"collection":[{"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/comments?post=11631"}],"version-history":[{"count":8,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/posts\/11631\/revisions"}],"predecessor-version":[{"id":12176,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/posts\/11631\/revisions\/12176"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/media\/11731"}],"wp:attachment":[{"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/media?parent=11631"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/categories?post=11631"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sitest.jp\/blog\/wp-json\/wp\/v2\/tags?post=11631"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}