{"id":198,"date":"2021-12-10T08:48:23","date_gmt":"2021-12-10T00:48:23","guid":{"rendered":"http:\/\/purplepoolobservatory.com\/?p=198"},"modified":"2021-12-10T08:48:23","modified_gmt":"2021-12-10T00:48:23","slug":"matplotlib%e7%bb%98%e5%88%b6%e6%97%a5%e6%9c%9f%e5%ba%8f%e5%88%97%e5%9b%be%e5%83%8f","status":"publish","type":"post","link":"https:\/\/purplepoolobservatory.com\/?p=198","title":{"rendered":"matplotlib\u7ed8\u5236\u65e5\u671f\u5e8f\u5217\u56fe\u50cf"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>import matplotlib.pyplot as plt\r\n\r\nimport matplotlib.dates as mdates\r\n\r\nimport datetime\r\n\r\n\r\n\r\nyears=mdates.YearLocator()\r\n\r\nmonths=mdates.MonthLocator()\r\n\r\nyearsFmt=mdates.DateFormatter('%Y')\r\n\r\nmag_min=np.zeros(len(mag_array))\r\n\r\nfig,ax=plt.subplots(nrows=2,ncols=1,figsize=(6,8))\r\n\r\nax&#91;0].vlines(date_array,mag_min,mag_array,lw=0.1) ### \u7ed8\u5236m-t\u56fe\r\n\r\nax&#91;0].set_xlim(datetime.datetime(2009,1,1),datetime.datetime(2018,2,28))\r\n\r\nax&#91;0].set_ylim(0,np.ceil(max(mag_array)))\r\n\r\nax&#91;0].xaxis.set_major_locator(years)  ### x\u5750\u6807\u4e3b\u6807\u8bb0\u523b\u5ea6\r\n\r\nax&#91;0].xaxis.set_major_formatter(yearsFmt)  ### x\u5750\u6807\u4e3b\u6807\u8bb0\u683c\u5f0f\r\n\r\nax&#91;0].xaxis.set_minor_locator(months) ### x\u5750\u6807\u6b21\u523b\u5ea6\r\n\r\nax&#91;0].set_xlabel('time')\r\n\r\nax&#91;0].set_ylabel('magnitude')\r\n\r\n\u200b\r\n\r\nax&#91;1].bar(date_markers,date_freq,width=35) ### \u7ed8\u5236n-t\u56fe\uff0c\u7528bar\u7ed8\u5236\u67f1\u72b6\u56fe\uff0c\u8fd9\u91ccdata_markers\u662fdatetime\u683c\u5f0f\u7684\u6708\u4efd\uff0c\u56e0\u6b64width\u898130\u5929\u5de6\u53f3\r\n\r\nax&#91;1].set_xlim(datetime.datetime(2009,1,1),datetime.datetime(2018,2,28))\r\n\r\n#ax&#91;1].set_ylim(0,np.ceil(max(date_freq)))\r\n\r\nax&#91;1].set_xlabel('time')\r\n\r\nax&#91;1].set_ylabel('monthly freq')\r\n\r\nplt.show()<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"gallery","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-198","post","type-post","status-publish","format-gallery","hentry","category-technology","post_format-post-format-gallery"],"_links":{"self":[{"href":"https:\/\/purplepoolobservatory.com\/index.php?rest_route=\/wp\/v2\/posts\/198","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/purplepoolobservatory.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/purplepoolobservatory.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/purplepoolobservatory.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/purplepoolobservatory.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=198"}],"version-history":[{"count":1,"href":"https:\/\/purplepoolobservatory.com\/index.php?rest_route=\/wp\/v2\/posts\/198\/revisions"}],"predecessor-version":[{"id":199,"href":"https:\/\/purplepoolobservatory.com\/index.php?rest_route=\/wp\/v2\/posts\/198\/revisions\/199"}],"wp:attachment":[{"href":"https:\/\/purplepoolobservatory.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=198"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/purplepoolobservatory.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=198"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/purplepoolobservatory.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=198"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}