{"id":53714,"date":"2025-08-12T16:19:59","date_gmt":"2025-08-12T08:19:59","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/53714.html"},"modified":"2025-08-12T16:19:59","modified_gmt":"2025-08-12T08:19:59","slug":"%e5%b0%8f%e6%9d%b0python%e9%ab%98%e7%ba%a7%ef%bc%88four-day%ef%bc%89-matplotlib%e5%ba%93","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/53714.html","title":{"rendered":"\u5c0f\u6770python\u9ad8\u7ea7\uff08four day\uff09\u2014\u2014matplotlib\u5e93"},"content":{"rendered":"<h2>1.\u7ed8\u5236\u5b50\u56fe\u7684\u65b9\u5f0f<\/h2>\n<li style=\"text-align:justify\"><span style=\"color:#333333\">pyplot\u4e2d\u51fd\u6570subplot<\/span><\/li>\n<li style=\"text-align:justify\"><span style=\"color:#333333\">Figure\u7c7b\u4e2d\u7684\u51fd\u6570add_subplot<\/span><\/li>\n<li style=\"text-align:justify\"><span style=\"color:#333333\">pyplot\u4e2d\u51fd\u6570subplots<\/span><\/li>\n<p><span style=\"background-color:#fafafa\"><span style=\"color:#000000\">fig<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> ax <\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\"> plt<\/span><span style=\"color:#999999\">.<\/span><span style=\"color:#000000\">subplots<\/span><span style=\"color:#999999\">(<\/span><span style=\"color:#000000\">nrows<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#990055\">1<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> ncols<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#990055\">1<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#9a6e3a\">*<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> sharex<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#990055\">False<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> sharey<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#990055\">False<\/span><span style=\"color:#999999\">,<br \/>\n<\/span><span style=\"color:#000000\"> squeeze<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#990055\">True<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> subplot_kw<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#990055\">None<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> gridspec_kw<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#990055\">None<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#9a6e3a\">**<\/span><span style=\"color:#000000\">fig_kw<\/span><span style=\"color:#999999\">)<\/span><br \/>\n<span style=\"color:#000000\">\u529f\u80fd&#xff1a;\u7ed8\u5236\u591a\u4e2a\u5b50\u56fe&#xff0c;\u53ef\u4ee5\u4e00\u6b21\u751f\u6210\u591a\u4e2a<\/span><br \/>\n<span style=\"color:#000000\">\u53c2\u6570&#xff1a;nrows\u548cncols&#xff1a;\u6574\u6570&#xff0c;\u8868\u793a\u5b50\u56fe\u7684\u884c\u6570\u548c\u5217\u6570\u3002<\/span><br \/>\n<span style=\"color:#000000\">      sharex\u548csharey&#xff1a;\u5e03\u5c14\u503c\u6216\u5b57\u7b26\u4e32&#xff0c;\u8868\u793a\u662f\u5426\u5171\u4eabx\u8f74\u6216y\u8f74\u7684\u5c5e\u6027\u3002            \u53ef\u9009\u503c\u6709<\/span><span style=\"color:#990055\">True<\/span><span style=\"color:#000000\">\u3001<\/span><span style=\"color:#990055\">False<\/span><span style=\"color:#000000\">\u3001<\/span><span style=\"color:#669900\">&#039;row&#039;<\/span><span style=\"color:#000000\">\u548c<\/span><span style=\"color:#669900\">&#039;col&#039;<\/span><span style=\"color:#000000\">\u3002<\/span><br \/>\n<span style=\"color:#000000\">      squeeze&#xff1a;\u5e03\u5c14\u503c&#xff0c;\u9ed8\u8ba4\u4e3a<\/span><span style=\"color:#990055\">True<\/span><span style=\"color:#000000\">\u3002\u5f53\u5b50\u56fe\u53ea\u6709\u4e00\u4e2a\u65f6&#xff0c;\u8fd4\u56de\u4e00\u4e2aAxes\u5bf9\u8c61<br \/>\n\u800c\u4e0d\u662f\u4e00\u4e2a\u6570\u7ec4\u3002<\/span><span style=\"color:#990055\">False<\/span><span style=\"color:#000000\">\u65f6\u8fd4\u56de\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4<\/span><br \/>\n<span style=\"color:#000000\">      width_ratios&#xff1a;\u5217\u5bbd\u6bd4\u4f8b\u7684\u5e8f\u5217&#xff0c;\u7528\u4e8e\u8c03\u6574\u5404\u5217\u7684\u5bbd\u5ea6\u6bd4<\/span><br \/>\n<span style=\"color:#000000\">      height_ratios&#xff1a;\u884c\u9ad8\u6bd4\u4f8b\u7684\u5e8f\u5217&#xff0c;\u7528\u4e8e\u8c03\u6574\u5404\u884c\u7684\u9ad8\u5ea6\u6bd4<\/span><br \/>\n<span style=\"color:#000000\">      subplot_kw&#xff1a;\u5b57\u5178\u7c7b\u578b&#xff0c;\u53ef\u9009\u53c2\u6570\u3002\u628a\u5b57\u5178\u7684\u5173\u952e\u5b57\u4f20\u9012\u7ed9add_subplot<\/span><span style=\"color:#999999\">()<br \/>\n<\/span><span style=\"color:#000000\">\u6765\u521b\u5efa\u6bcf\u4e2a\u5b50\u56fe\u3002<\/span><br \/>\n<span style=\"color:#000000\">      gridspec_kw&#xff1a;\u5b57\u5178\u7c7b\u578b&#xff0c;\u53ef\u9009\u53c2\u6570\u3002\u628a\u5b57\u5178\u7684\u5173\u952e\u5b57\u4f20\u9012\u7ed9GridSpec\u6784\u9020\u51fd\u6570<br \/>\n\u521b\u5efa\u5b50\u56fe\u653e\u5728\u7f51\u683c\u91cc&#xff08;grid&#xff09;\u3002<\/span><br \/>\n      <span style=\"color:#9a6e3a\">**<\/span><span style=\"color:#000000\">fig_kw&#xff1a;\u628a\u6240\u6709\u8be6\u7ec6\u7684\u5173\u952e\u5b57\u53c2\u6570\u4f20\u7ed9figure<\/span><span style=\"color:#999999\">()<\/span><span style=\"color:#000000\">\u51fd\u6570\u3002<\/span><br \/>\n<span style=\"color:#000000\">\u8fd4\u56de\u503c&#xff1a;fig&#xff1a;\u8fd9\u662f\u6574\u4e2a\u56fe\u5f62\u7684\u5bf9\u8c61&#xff0c;\u53ef\u4ee5\u5bf9\u5176\u8fdb\u884c\u5168\u5c40\u8bbe\u7f6e&#xff0c;\u5982\u6807\u9898\u3001\u5927\u5c0f\u7b49\u3002<\/span><br \/>\n<span style=\"color:#000000\">        axes&#xff1a;\u8fd9\u662f\u4e00\u4e2a\u6570\u7ec4&#xff0c;\u5305\u542b\u6240\u6709\u7684\u5b50\u56fe\u3002\u6570\u7ec4\u7684\u5f62\u72b6\u7531nrows\u548cncols\u51b3\u5b9a\u3002<br \/>\n\u4f8b\u5982&#xff0c;\u5982\u679c nrows<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#990055\">2<\/span><span style=\"color:#000000\"> \u548c ncols<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#990055\">3<\/span><span style=\"color:#000000\">&#xff0c;\u5219 axes \u5c06\u662f\u4e00\u4e2a 2&#215;3 \u7684\u6570\u7ec4&#xff0c;\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u4e00\u4e2a<br \/>\n\u5b50\u56fe\u5bf9\u8c61\u3002<\/span><br \/>\n<\/span><\/p>\n<p># \u7ed8\u5236\u5b50\u56fe&#xff0c;\u8fd4\u56de\u503c\u5305\u542bFigure\u5bf9\u8c61\u548cAxes\u5bf9\u8c61&#xff0c;Axes\u5bf9\u8c61\u662f\u4e00\u4e2a\u6570\u7ec4&#xff0c;\u53ef\u4ee5\u901a\u8fc7\u4e0b\u6807\u8fdb\u884c\u8bbf\u95ee\u5b50\u56fe<br \/>\nfig, ax &#061; plt.subplots(2, 2)<\/p>\n<p>ax[0, 0].plot([2,3], [4,5])<br \/>\nax[0, 1].plot([1,1], [2,1])<\/p>\n<p>fig.suptitle(&#039;sub&#039;)<\/p>\n<p>plt.show()<\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\">\n<h2 style=\"margin-left:0px;margin-right:0px;text-align:justify\">2.pyplot\u4e2d\u5e38\u7528\u51fd\u6570<\/h2>\n<h5><\/h5>\n<h5><span style=\"background-color:#ffd900\">gcf<\/span><\/h5>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#333333\">\u529f\u80fd&#xff1a;\u83b7\u53d6<\/span><span style=\"color:#333333\">\u5f53\u524d<\/span><span style=\"color:#333333\">\u7a97\u53e3<\/span><span style=\"color:#333333\">\u7684<\/span><span style=\"color:#333333\">Figure<\/span><span style=\"color:#333333\">\u5bf9\u8c61<\/span><span style=\"color:#333333\">&#xff0c;<\/span><span style=\"color:#333333\">\u5982\u679c\u6ca1\u6709\u6d3b\u52a8\u7684\u56fe\u5f62&#xff0c;\u8fd9\u4e2a\u51fd\u6570\u5c06\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u56fe\u5f62&#xff0c;\u5e76\u5c06\u5176\u4f5c\u4e3a\u5f53\u524d\u6d3b\u52a8\u7684\u56fe\u5f62\u3002\u901a\u8fc7\u6b64\u51fd\u6570\u83b7\u53d6\u4e86\u5f53\u524d\u56fe\u5f62\u7684Figure\u5bf9\u8c61\u540e&#xff0c;\u53ef\u4ee5\u8c03\u7528Figure\u7c7b\u4e2d\u7684\u76f8\u5173\u64cd\u4f5c<\/span><\/p>\n<h5><span style=\"background-color:#ffd900\">gca<\/span><\/h5>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#333333\">\u529f\u80fd&#xff1a;\u83b7\u53d6<\/span><span style=\"color:#333333\">\u83b7\u53d6\u5f53\u524d\u56fe\u5f62\u4e2d\u7684<\/span><span style=\"color:#333333\">Axes<\/span><span style=\"color:#333333\">\u5bf9\u8c61<\/span><\/p>\n<p>x &#061; np.arange(0, 2*np.pi, 0.1)<br \/>\ny &#061; np.sin(x)<br \/>\nplt.plot(x, y, label&#061;&#039;sin&#039;)<br \/>\n# \u83b7\u53d6Figure\u5bf9\u8c61<br \/>\nfig &#061; plt.gcf()<br \/>\nfig.suptitle(&#039;sin&#039;)<br \/>\n# \u83b7\u53d6Axes\u5bf9\u8c61<br \/>\nax &#061; plt.gca()<br \/>\nax.set_xlabel(&#039;x&#039;)<\/p>\n<p>plt.show()<\/p>\n<h5><span style=\"background-color:#ffd900\">savefig<\/span><\/h5>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#333333\">matplotlib.pyplot \u6a21\u5757\u4e2d\u7684<span style=\"background-color:null\"> savefig<\/span> \u51fd\u6570\u7528\u4e8e\u5c06\u5f53\u524d\u56fe\u5f62\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">plt.<\/span><span style=\"color:#dd4a68\">savefig<\/span><span style=\"color:#999999\">(<\/span><span style=\"color:#000000\">*args<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> **kwargs<\/span><span style=\"color:#999999\">)<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u53c2\u6570&#xff1a;<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0fname&#xff1a;\u5b57\u7b26\u4e32\u6216\u7c7b\u4f3c\u6587\u4ef6\u7684\u5bf9\u8c61&#xff0c;\u6307\u5b9a\u4fdd\u5b58\u6587\u4ef6\u7684\u8def\u5f84\u6216\u6587\u4ef6\u540d\u3002\u53ef\u4ee5\u662f\u76f8\u5bf9\u8def\u5f84\u6216\u7edd\u5bf9\u8def\u5f84\u3002\u5982\u679c\u6587\u4ef6\u6269\u5c55\u540d\u7f3a\u5931&#xff0c;\u5c06\u4f7f\u7528\u9ed8\u8ba4\u683c\u5f0f&#xff08;\u901a\u5e38\u662f PNG&#xff09;\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0dpi&#xff1a;\u53ef\u9009&#xff0c;\u6307\u5b9a\u4fdd\u5b58\u56fe\u50cf\u7684dpi<\/span><span style=\"color:#000000\">&#xff08;\u6bcf\u82f1\u5bf8\u70b9\u6570&#xff09;\u3002\u9ed8\u8ba4\u503c\u662ffigure.dpi\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0format&#xff1a;\u53ef\u9009&#xff0c;\u6307\u5b9a\u6587\u4ef6\u683c\u5f0f&#xff08;\u5982 <\/span><span style=\"color:#669900\">&#039;png&#039;<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#669900\">&#039;pdf&#039;<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#669900\">&#039;svg&#039;<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#669900\">&#039;ps&#039;<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#669900\">&#039;eps&#039;<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> &#8230;&#xff09;\u3002\u5982\u679c\u7701\u7565&#xff0c;\u5c06\u4f7f\u7528\u6587\u4ef6\u6269\u5c55\u540d\u63a8\u65ad\u683c\u5f0f\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0bbox_inches&#xff1a;\u53ef\u9009&#xff0c;\u6307\u5b9a\u88c1\u526a\u6846&#xff0c;\u53ef\u4ee5\u662f <\/span><span style=\"color:#669900\">&#039;tight&#039;<\/span><span style=\"color:#000000\">\u3001<\/span><span style=\"color:#669900\">&#039;standard&#039;<\/span><span style=\"color:#000000\"> \u6216\u4e00\u4e2a Bbox \u5bf9\u8c61\u3002\u9ed8\u8ba4\u4e3a <\/span><span style=\"color:#669900\">&#039;standard&#039;<\/span><span style=\"color:#000000\">\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color:#990055\">tight<\/span><span style=\"color:#999999\">:<\/span><span style=\"color:#000000\">\u4fdd\u5b58\u7684\u56fe\u5f62\u6587\u4ef6\u4e2d\u4e0d\u4f1a\u6709\u4e0d\u5fc5\u8981\u7684\u7a7a\u767d\u8fb9\u7f18&#xff0c;\u4f7f\u5f97\u56fe\u5f62\u66f4\u52a0\u7d27\u51d1\u548c\u6574\u6d01<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pad_inches&#xff1a;\u53ef\u9009&#xff0c;\u6307\u5b9a\u8fb9\u6846\u586b\u5145\u91cf&#xff08;\u4ee5\u82f1\u5bf8\u4e3a\u5355\u4f4d&#xff09;\u3002\u9ed8\u8ba4\u4e3a 0.1\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0facecolor&#xff1a;\u53ef\u9009&#xff0c;\u6307\u5b9a\u56fe\u50cf\u7684\u80cc\u666f\u989c\u8272\u3002\u9ed8\u8ba4\u4e3a <\/span><span style=\"color:#669900\">&#039;w&#039;<\/span><span style=\"color:#000000\">&#xff08;\u767d\u8272&#xff09;\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0edgecolor&#xff1a;\u53ef\u9009&#xff0c;\u6307\u5b9a\u56fe\u50cf\u8fb9\u6846\u7684\u989c\u8272\u3002\u9ed8\u8ba4\u4e3a <\/span><span style=\"color:#669900\">&#039;w&#039;<\/span><span style=\"color:#000000\">&#xff08;\u767d\u8272&#xff09;\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0orientation&#xff1a;\u53ef\u9009&#xff0c;\u6307\u5b9a\u9875\u9762\u65b9\u5411&#xff08;<\/span><span style=\"color:#669900\">&#039;portrait&#039;<\/span><span style=\"color:#000000\"> \u6216 <\/span><span style=\"color:#669900\">&#039;landscape&#039;<\/span><span style=\"color:#000000\">&#xff09;&#xff0c;\u4ec5\u5bf9\u4fdd\u5b58\u4e3a PDF \u6587\u4ef6\u65f6\u6709\u6548\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0papertype&#xff1a;\u53ef\u9009&#xff0c;\u6307\u5b9a\u7eb8\u5f20\u7c7b\u578b&#xff08;\u5982 <\/span><span style=\"color:#669900\">&#039;a4&#039;<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#669900\">&#039;letter&#039;<\/span><span style=\"color:#000000\">&#xff09;&#xff0c;\u4ec5\u5bf9\u4fdd\u5b58\u4e3a PDF \u6587\u4ef6\u65f6\u6709\u6548\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0format_kwargs&#xff1a;\u53ef\u9009&#xff0c;\u5176\u4ed6\u4e0e\u683c\u5f0f\u76f8\u5173\u7684\u5173\u952e\u5b57\u53c2\u6570\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0metadata&#xff1a;\u53ef\u9009&#xff0c;\u6307\u5b9a\u8981\u5199\u5165\u6587\u4ef6\u7684\u5143\u6570\u636e\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pil_kwargs \u548c pdf_kwargs&#xff1a;\u53ef\u9009&#xff0c;\u7279\u5b9a\u4e8e PIL \u6216 PDF \u683c\u5f0f\u7684\u53c2\u6570\u3002<\/span><\/p>\n<p>x &#061; np.arange(0, 2*np.pi, 0.1)<br \/>\ny &#061; np.sin(x)<br \/>\nplt.plot(x, y, label&#061;&#039;sin&#039;)<\/p>\n<p>y &#061; np.cos(x)<br \/>\nplt.plot(x, y, label&#061;&#039;cos&#039;)<br \/>\n# \u9690\u85cf\u5750\u6807\u8f74<br \/>\nplt.axis(&#039;off&#039;)<br \/>\n# \u4fdd\u5b58\u56fe\u7247<br \/>\nplt.savefig(&#039;.\/sin.png&#039;)<\/p>\n<h5><span style=\"background-color:#ffd900\">imsave<\/span><\/h5>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#333333\">\u7528\u4e8e\u5c06\u56fe\u50cf\u6570\u636e\u4fdd\u5b58\u5230\u78c1\u76d8\u4e0a\u7684\u51fd\u6570<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">matplotlib.pyplot.<\/span><span style=\"color:#dd4a68\">imsave<\/span><span style=\"color:#999999\">(<\/span><span style=\"color:#000000\">fname<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> arr<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> **kwargs<\/span><span style=\"color:#999999\">)<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u53c2\u6570&#xff1a;fname&#xff1a;\u4fdd\u5b58\u56fe\u50cf\u7684\u6587\u4ef6\u540d&#xff0c;\u53ef\u4ee5\u662f\u76f8\u5bf9\u8def\u5f84\u6216\u7edd\u5bf9\u8def\u5f84\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0arr&#xff1a;\u8868\u793a\u56fe\u50cf\u7684NumPy\u6570\u7ec4\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0kwargs&#xff1a;\u53ef\u9009\u53c2\u6570&#xff0c;\u7528\u4e8e\u6307\u5b9a\u4fdd\u5b58\u7684\u56fe\u50cf\u683c\u5f0f\u4ee5\u53ca\u56fe\u50cf\u8d28\u91cf\u7b49\u53c2\u6570\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#333333\"><span style=\"background-color:#ffd900\">imsave\u548csavefig\u533a\u522b<\/span><\/span><span style=\"color:#333333\">&#xff1a;<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#333333\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0savefig\u53ef\u4ee5<\/span><span style=\"color:#333333\">\u5c06<\/span><span style=\"color:#333333\">\u7ed8\u5236<\/span><span style=\"color:#333333\">\u7684<\/span><span style=\"color:#333333\"><span style=\"background-color:#ffd900\">\u56fe\u50cf<\/span><\/span><span style=\"color:#333333\"><span style=\"background-color:#ffd900\">\u4fdd\u5b58<\/span><\/span><span style=\"color:#333333\"><span style=\"background-color:#ffd900\">\u6210<\/span><\/span><span style=\"color:#333333\"><span style=\"background-color:#ffd900\">\u6587\u4ef6<\/span><\/span><span style=\"color:#333333\">&#xff0c;<\/span><span style=\"color:#333333\">\u5305\u542b<\/span><span style=\"color:#333333\"><span style=\"background-color:#ffd900\">\u5750\u6807<\/span><\/span><span style=\"color:#333333\">\u3001<\/span><span style=\"color:#333333\">\u6807\u9898<\/span><span style=\"color:#333333\">\u3001<\/span><span style=\"color:#333333\">\u56fe\u4f8b<\/span><span style=\"color:#333333\">\u7b49<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#333333\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0imsave\u662f<\/span><span style=\"color:#333333\">\u5c06<span style=\"background-color:#ffd900\">\u4e8c\u7ef4\u6216\u4e09\u7ef4\u6570\u636e<\/span><\/span><span style=\"color:#333333\"><span style=\"background-color:#ffd900\">\u4fdd\u5b58<\/span><\/span><span style=\"color:#333333\"><span style=\"background-color:#ffd900\">\u6210<\/span><\/span><span style=\"color:#333333\"><span style=\"background-color:#ffd900\">\u56fe\u50cf\u6587\u4ef6<\/span><\/span><span style=\"color:#333333\">&#xff0c;<\/span><span style=\"color:#333333\"><span style=\"background-color:#ffd900\">\u4e0d\u542b<\/span><\/span><span style=\"color:#333333\"><span style=\"background-color:#ffd900\">\u5750\u6807<\/span><\/span><span style=\"color:#333333\">\u7b49<\/span><span style=\"color:#333333\">&#xff0c;<\/span><span style=\"color:#333333\">\u5b83<\/span><span style=\"color:#333333\">\u6ca1\u6cd5<\/span><span style=\"color:#333333\">\u76f4\u63a5<\/span><span style=\"color:#333333\">\u4fdd\u5b58plot\u7b49\u7ed8\u5236<\/span><span style=\"color:#333333\">\u7684<\/span><span style=\"color:#333333\">\u56fe\u50cf<\/span><\/p>\n<p>arr &#061; np.array([[1,2,3,1], [2,3,1,2]])<br \/>\n# \u7ed8\u5236\u4e8c\u7ef4\u6216\u4e09\u7ef4\u6570\u636e\u56fe\u50cf,\u901a\u8fc7cmap\u8fdb\u884c\u989c\u8272\u6620\u5c04<br \/>\nplt.imshow(arr, cmap&#061;&#039;gray&#039;)<br \/>\nplt.imsave(&#039;.\/test.png&#039;, arr)<br \/>\nplt.show()<\/p>\n<h5><span style=\"background-color:#ffd900\">imshow<\/span><\/h5>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#333333\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0imshow() \u51fd\u6570\u662f Matplotlib.pyplot \u5e93\u4e2d\u7684\u4e00\u4e2a\u51fd\u6570&#xff0c;\u5b83\u5e38\u7528\u4e8e\u7ed8\u5236\u4e8c\u7ef4\u7684\u7070\u5ea6\u56fe\u50cf\u6216\u5f69\u8272\u56fe\u50cf&#xff0c;\u4e5f\u53ef\u4ee5\u7528\u4e8e\u7ed8\u5236\u77e9\u9635\u3001\u70ed\u529b\u56fe\u3001\u5730\u56fe\u7b49\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">imshow<\/span><span style=\"color:#999999\">(<\/span><span style=\"color:#000000\">X<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> cmap<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> norm<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> aspect<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> interpolation<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> alpha<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> vmin<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> vmax<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> origin<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> extent<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> shape<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> filternorm<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#990055\">1<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> filterrad<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#990055\">4.0<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> imlim<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> resample<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> url<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#9a6e3a\">*<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#0077aa\">data<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#9a6e3a\">**<\/span><span style=\"color:#000000\">kwargs<\/span><span style=\"color:#999999\">)<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u53c2\u6570&#xff1a;X&#xff1a;\u56fe\u50cf\u6570\u636e\u3002\u8fd9\u901a\u5e38\u662f\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4&#xff08;\u7070\u5ea6\u56fe\u50cf&#xff09;\u6216\u4e00\u4e2a\u4e09\u7ef4\u6570\u7ec4&#xff08;\u5f69\u8272\u56fe\u50cf&#xff0c;\u5176\u4e2d\u7b2c\u4e09\u7ef4\u662f\u989c\u8272\u901a\u9053&#xff09;\u3002\u5bf9\u4e8e\u4e8c\u7ef4\u6570\u7ec4&#xff0c;\u53ef\u4ee5\u4f7f\u7528 cmap \u53c2\u6570\u6765\u6307\u5b9a\u989c\u8272\u6620\u5c04<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0cmap&#xff1a;\u989c\u8272\u6620\u5c04\u3002\u7528\u4e8e\u63a7\u5236\u56fe\u50cf\u4e2d\u4e0d\u540c\u6570\u503c\u6240\u5bf9\u5e94\u7684\u989c\u8272\u3002\u9ed8\u8ba4\u989c\u8272\u662f<\/span><span style=\"color:#669900\">&#039;viridis&#039;<\/span><span style=\"color:#000000\">&#xff0c;\u4e5f\u53ef\u4ee5\u8bbe\u7f6e\u5176\u4ed6\u989c\u8272&#xff0c;\u5982&#096;gray&#096;\u3001&#096;hot&#096;\u3001&#096;jet&#096;\u3001<\/span><span style=\"color:#669900\">&#039;binary&#039;<\/span><span style=\"color:#000000\">\u7b49 <\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0norm&#xff1a;\u7528\u4e8e\u5c06\u6570\u636e\u503c\u6807\u51c6\u5316\u5230 [<\/span><span style=\"color:#990055\">0<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#990055\">1<\/span><span style=\"color:#000000\">] \u533a\u95f4\u3002\u4ee5\u4fbf\u4e0e\u989c\u8272\u6620\u5c04\u4e00\u8d77\u4f7f\u7528\u3002\u5982\u679c\u4e3a None&#xff0c;\u5219\u6570\u636e\u5c06\u76f4\u63a5\u7528\u4e8e\u989c\u8272\u6620\u5c04\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0aspect&#xff1a;\u63a7\u5236\u56fe\u50cf\u5bbd\u9ad8\u6bd4<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#669900\">&#039;auto&#039;<\/span><span style=\"color:#000000\">&#xff08;\u9ed8\u8ba4&#xff0c;\u6839\u636e\u6570\u636e\u5f62\u72b6\u81ea\u52a8\u8c03\u6574&#xff09;\u3001<\/span><span style=\"color:#669900\">&#039;equal&#039;<\/span><span style=\"color:#000000\">&#xff08;\u4f7f\u50cf\u7d20\u4e3a\u6b63\u65b9\u5f62&#xff09;\u6216\u6570\u5b57&#xff08;\u6307\u5b9a\u5bbd\u9ad8\u6bd4&#xff09;<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0interpolation&#xff1a;\u63d2\u503c\u65b9\u6cd5\u3002\u7528\u4e8e\u63a7\u5236\u56fe\u50cf\u7684\u5e73\u6ed1\u7a0b\u5ea6\u548c\u7ec6\u8282\u7a0b\u5ea6\u3002\u53ef\u4ee5\u9009\u62e9&#096;nearest&#096;\u3001&#096;bilinear&#096;\u3001&#096;bicubic&#096;\u7b49\u63d2\u503c\u65b9\u6cd5\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0alpha&#xff1a;\u56fe\u50cf\u900f\u660e\u5ea6\u3002\u53d6\u503c\u8303\u56f4\u4e3a<\/span><span style=\"color:#990055\">0<\/span><span style=\"color:#000000\">~<\/span><span style=\"color:#990055\">1<\/span><span style=\"color:#000000\">\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0origin&#xff1a;\u5750\u6807\u8f74\u539f\u70b9\u7684\u4f4d\u7f6e\u3002\u53ef\u4ee5\u8bbe\u7f6e\u4e3a&#096;upper&#096;\u6216&#096;lower&#096;\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0extent&#xff1a;\u63a7\u5236\u663e\u793a\u7684\u6570\u636e\u8303\u56f4\u3002\u53ef\u4ee5\u8bbe\u7f6e\u4e3a&#096;[xmin<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> xmax<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> ymin<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> ymax]&#096;\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0vmin\u3001vmax&#xff1a;\u63a7\u5236\u989c\u8272\u6620\u5c04\u7684\u503c\u57df\u8303\u56f4\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0 \u00a0 \u00a0 \u00a0filternorm \u548c filterrad&#xff1a;\u7528\u4e8e\u56fe\u50cf\u6ee4\u6ce2\u7684\u5bf9\u8c61\u3002\u53ef\u4ee5\u8bbe\u7f6e\u4e3a&#096;None&#096;\u3001&#096;antigrain&#096;\u3001&#096;freetype&#096;\u7b49\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0imlim&#xff1a; \u7528\u4e8e\u6307\u5b9a\u56fe\u50cf\u663e\u793a\u8303\u56f4\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0resample&#xff1a;\u7528\u4e8e\u6307\u5b9a\u56fe\u50cf\u91cd\u91c7\u6837\u65b9\u5f0f\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0url&#xff1a;\u7528\u4e8e\u6307\u5b9a\u56fe\u50cf\u94fe\u63a5\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\">\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">plt.colorbar<\/span><span style=\"color:#999999\">()<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u529f\u80fd&#xff1a;\u663e\u793a\u989c\u8272\u67f1<\/span><\/p>\n<h5><span style=\"background-color:#ffd900\">imread<\/span><\/h5>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#333333\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0imread() \u65b9\u6cd5\u662f Matplotlib \u5e93\u4e2d\u7684\u4e00\u4e2a\u51fd\u6570&#xff0c;\u7528\u4e8e\u4ece\u56fe\u50cf\u6587\u4ef6\u4e2d\u8bfb\u53d6\u56fe\u50cf\u6570\u636e\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#333333\">imread() \u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a numpy.ndarray \u5bf9\u8c61&#xff0c;\u5176\u5f62\u72b6\u662f (nrows, ncols, nchannels)&#xff0c;\u8868\u793a\u8bfb\u53d6\u7684\u56fe\u50cf\u7684\u884c\u6570\u3001\u5217\u6570\u548c\u901a\u9053\u6570&#xff1a;<\/span><\/p>\n<li style=\"text-align:justify\"><span style=\"color:#333333\">\u5982\u679c\u56fe\u50cf\u662f\u7070\u5ea6\u56fe\u50cf&#xff0c;\u5219 nchannels \u4e3a 1\u3002<\/span><\/li>\n<li style=\"text-align:justify\"><span style=\"color:#333333\">\u5982\u679c\u662f\u5f69\u8272\u56fe\u50cf&#xff0c;\u5219 nchannels \u4e3a 3 \u6216 4&#xff0c;\u5206\u522b\u8868\u793a\u7ea2\u3001\u7eff\u3001\u84dd\u4e09\u4e2a\u989c\u8272\u901a\u9053\u548c\u4e00\u4e2a alpha \u901a\u9053&#xff1b;\u4e3a3\u65f6\u8868\u793a\u7ea2\u7eff\u84dd&#xff0c;\u4e3a4\u65f6\u8868\u793a\u7ea2\u7eff\u84dd\u3001\u900f\u660e\u5ea6\u3002<\/span><\/li>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">matplotlib<\/span><span style=\"color:#9a6e3a\">.pyplot.<\/span><span style=\"color:#000000\">imread<\/span><span style=\"color:#999999\">(<\/span><span style=\"color:#000000\">fname<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#0077aa\">format<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">)<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u53c2\u6570&#xff1a;fname&#xff1a;\u6307\u5b9a\u4e86\u8981\u8bfb\u53d6\u7684\u56fe\u50cf\u6587\u4ef6\u7684\u6587\u4ef6\u540d\u6216\u6587\u4ef6\u8def\u5f84&#xff0c;\u53ef\u4ee5\u662f\u76f8\u5bf9\u8def\u5f84\u6216\u7edd\u5bf9\u8def\u5f84\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#0077aa\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0format<\/span><span style=\"color:#000000\">&#xff1a;\u53c2\u6570\u6307\u5b9a\u4e86\u56fe\u50cf\u6587\u4ef6\u7684\u683c\u5f0f&#xff0c;\u5982\u679c\u4e0d\u6307\u5b9a&#xff0c;\u5219\u9ed8\u8ba4\u6839\u636e\u6587\u4ef6\u540e\u7f00\u540d\u6765\u81ea\u52a8\u8bc6\u522b\u683c\u5f0f\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u8fd4\u56de\u503c&#xff1a;numpy.ndarray \u5bf9\u8c61<\/span><\/p>\n<p>arr &#061; plt.imread(&#039;map.png&#039;)<br \/>\nplt.imshow(arr)<br \/>\nplt.show()<\/p>\n<h5><span style=\"background-color:#ffd900\">close<\/span><\/h5>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">plt.close(fig&#061;None)<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u529f\u80fd&#xff1a;\u8be5\u51fd\u6570\u7528\u4e8e\u5173\u95ed\u4e00\u4e2a\u6216\u591a\u4e2a\u6253\u5f00\u7684\u56fe\u5f62\u7a97\u53e3&#xff0c;\u91ca\u653e\u8d44\u6e90<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u53c2\u6570&#xff1a;fig&#xff1a;\u6307\u5b9a\u8981\u5173\u95ed\u7684\u56fe\u5f62&#xff0c;\u53ef\u4ee5\u662fFigure\u5bf9\u8c61&#xff0c;\u4e5f\u53ef\u4ee5\u662f\u56fe\u5f62\u5bf9\u5e94\u7684\u6574\u6570<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0all&#xff1a;\u5173\u95ed\u6240\u6709\u56fe\u5f62&#xff0c;\u5982\u679c\u53c2\u6570\u7701\u7565&#xff0c;\u5173\u95ed\u5f53\u524d\u56fe\u50cf<\/span><\/p>\n<h3><\/h3>\n<h5>Line2D\u00a0 \u7c7b\u51fd\u6570<\/h5>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#333333\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0plt.plot\u51fd\u6570\u7684\u8fd4\u56de\u503c\u8868\u793a\u5305\u542b\u4e00\u4e2a\u6216\u591a\u4e2a Line2D \u5bf9\u8c61<\/span><span style=\"color:#333333\">&#xff08;\u6709\u591a\u6761\u7ebf\u65f6\u4f1a\u8fd4\u56de\u591a\u4e2aLine2D\u5bf9\u8c61&#xff09;<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#333333\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Line2D \u662f Matplotlib \u4e2d\u7528\u4e8e\u8868\u793a\u4e8c\u7ef4\u7ebf\u6761\u7684\u7c7b\u3002\u901a\u8fc7\u8fd4\u56de Line2D \u5bf9\u8c61&#xff0c;\u4f60\u53ef\u4ee5\u8bbf\u95ee\u548c\u4fee\u6539\u7ebf\u6761\u7684\u5404\u79cd\u5c5e\u6027&#xff0c;\u4f8b\u5982\u989c\u8272\u3001\u7ebf\u578b\u3001\u6807\u7b7e\u7b49\u3002\u8fd9\u4f7f\u5f97 plt.plot() \u4e0d\u4ec5\u4ec5\u662f\u7ed8\u5236\u56fe\u5f62&#xff0c;\u8fd8\u53ef\u4ee5\u8ba9\u4f60\u5bf9\u7ed8\u5236\u7684\u7ebf\u6761\u8fdb\u884c\u8fdb\u4e00\u6b65\u7684\u5b9a\u5236\u3002<\/span><\/p>\n<h6><span style=\"background-color:#ffd900\">get_label<\/span><\/h6>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#333333\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8be5\u65b9\u6cd5\u7528\u4e8e\u83b7\u53d6\u56fe\u50cf<\/span><span style=\"color:#333333\">\u7684<\/span><span style=\"color:#333333\">\u6807\u7b7e<\/span><span style=\"color:#333333\">&#xff08;\u53c2\u6570\u4e2d\u6307\u5b9a\u7684label\u503c&#xff09;<\/span><span style=\"color:#333333\">\u3002\u8fd9\u4e2a\u65b9\u6cd5\u901a\u5e38\u7528\u4e8e\u83b7\u53d6\u5df2\u7ecf\u8bbe\u7f6e\u597d\u7684\u6807\u7b7e&#xff0c;\u4ee5\u4fbf\u4e8e\u540e\u7eed\u7684\u68c0\u67e5\u6216\u4fee\u6539.<\/span><\/p>\n<h6><span style=\"background-color:#ffd900\">set_data<\/span><\/h6>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#333333\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8be5\u51fd\u6570\u529f\u80fd\u4e3a\u7528\u4e8e\u52a8\u6001\u66f4\u65b0\u7ebf\u6761\u7684 x \u548c y \u6570\u636e\u3002\u4e3b\u8981\u5728\u9700\u8981\u5b9e\u65f6\u66f4\u65b0\u56fe\u5f62&#xff08;\u4f8b\u5982\u52a8\u753b&#xff09;\u7684\u573a\u666f\u4e2d\u3002<\/span><\/p>\n<p><span style=\"background-color:#fafafa\"><span style=\"color:#000000\">Line2D.set_<\/span><span style=\"color:#dd4a68\">data<\/span><span style=\"color:#999999\">(<\/span><span style=\"color:#000000\">xdata<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> ydata<\/span><span style=\"color:#999999\">)<\/span><\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#333333\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8c03\u7528\u8be5\u65b9\u6cd5\u540e&#xff0c;\u56fe\u5f62\u4f1a\u6839\u636e\u65b0\u7684\u6570\u636e\u91cd\u65b0\u7ed8\u5236\u3002\u5b83\u4e0d\u4f1a\u81ea\u52a8\u5237\u65b0\u56fe\u5f62&#xff0c;\u4f46\u53ef\u4ee5\u4e0e plt.draw() \u6216 plt.pause() \u7b49\u65b9\u6cd5\u7ed3\u5408\u4f7f\u7528&#xff0c;\u4ee5\u5b9e\u73b0\u52a8\u6001\u66f4\u65b0\u7684\u6548\u679c\u3002<\/span><\/p>\n<h5><span style=\"background-color:#ffd900\">pause<\/span><\/h5>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#333333\">\u7528\u4e8e\u5728\u7ed8\u56fe\u65f6\u6682\u505c\u7a0b\u5e8f\u6267\u884c&#xff0c;\u5e76\u5728\u6307\u5b9a\u7684\u65f6\u95f4\u95f4\u9694\u540e\u7ee7\u7eed\u6267\u884c\u3002\u5b83\u5e38\u7528\u4e8e\u52a8\u6001\u66f4\u65b0\u56fe\u5f62\u6216\u521b\u5efa\u7b80\u5355\u7684\u52a8\u753b\u6548\u679c\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#333333\">\u51fd\u6570\u7684\u4f5c\u7528&#xff1a;<\/span><\/p>\n<ul>\n<li style=\"text-align:justify\"><span style=\"color:#333333\">\u6682\u505c\u7a0b\u5e8f<\/span><span style=\"color:#333333\">&#xff1a;plt.pause(interval) \u4f1a\u6682\u505c\u7a0b\u5e8f\u7684\u6267\u884c&#xff0c;\u6682\u505c\u7684\u65f6\u95f4\u7531\u53c2\u6570 interval&#xff08;\u5355\u4f4d\u4e3a\u79d2&#xff09;\u51b3\u5b9a\u3002<\/span><\/li>\n<li style=\"text-align:justify\"><span style=\"color:#333333\">\u5237\u65b0\u56fe\u5f62\u7a97\u53e3<\/span><span style=\"color:#333333\">&#xff1a;\u5728\u6682\u505c\u671f\u95f4&#xff0c;plt.pause() \u4f1a\u5f3a\u5236\u5237\u65b0\u56fe\u5f62\u7a97\u53e3&#xff0c;\u663e\u793a\u6700\u65b0\u7684\u56fe\u5f62\u5185\u5bb9\u3002\u8fd9\u4f7f\u5f97\u5b83\u7279\u522b\u9002\u5408\u7528\u4e8e\u52a8\u6001\u66f4\u65b0\u56fe\u5f62\u7684\u573a\u666f\u3002<\/span><\/li>\n<\/ul>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#333333\">\u51fd\u6570\u539f\u578b&#xff1a;<\/span><\/p>\n<p><span style=\"background-color:#fafafa\"><span style=\"color:#000000\">pyplot.pause<\/span><span style=\"color:#999999\">(<\/span><span style=\"color:#000000\">interval<\/span><span style=\"color:#999999\">)<\/span><br \/>\n<span style=\"color:#000000\">\u53c2\u6570&#xff1a;interval&#xff1a;\u65f6\u95f4&#xff0c;\u79d2<\/span><br \/>\n<\/span><\/p>\n<p>x &#061; np.arange(0, 2*np.pi, 0.1)<br \/>\ny &#061; np.sin(x)<br \/>\nld, &#061; plt.plot(x, y, label&#061;&#039;sin&#039;)<\/p>\n<p># \u83b7\u53d6\u56fe\u50cf\u4e2dlabel\u6570\u636e<br \/>\n# ret &#061; ld.get_label()<br \/>\n# print(ret)<\/p>\n<p>y &#061; np.cos(x)<br \/>\n# \u6839\u636e\u6307\u5b9a\u7684\u65f6\u95f4\u6682\u505c\u7a0b\u5e8f<br \/>\nplt.pause(5)<br \/>\n# \u4fee\u6539\u539f\u56fe\u50cf\u7684\u6570\u636e<br \/>\nld.set_data(x, y)<\/p>\n<p>plt.show()<\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\">\n<h2 style=\"margin-left:0px;margin-right:0px;text-align:justify\">3.\u7ed8\u5236\u5b50\u56fe\u7f51\u683c<\/h2>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#333333\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4f7f\u7528\u6a21\u5757gridspec\u4e2d\u7684\u51fd\u6570GridSpec\u7ed8\u5236<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#333333\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5728 Matplotlib \u4e2d&#xff0c;GridSpec \u5bf9\u8c61\u63d0\u4f9b\u4e86\u4e00\u79cd\u7075\u6d3b\u7684\u65b9\u5f0f\u6765\u521b\u5efa\u5b50\u56fe\u7f51\u683c&#xff08;subplots grid&#xff09;&#xff0c;\u5141\u8bb8\u5b50\u56fe\u8de8\u8d8a\u591a\u4e2a\u884c\u548c\u5217&#xff0c;\u4ee5\u53ca\u5177\u6709\u4e0d\u5747\u5300\u7684\u884c\u9ad8\u548c\u5217\u5bbd\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#0077aa\">from<\/span><span style=\"color:#000000\"> matplotlib<\/span><span style=\"color:#999999\">.<\/span><span style=\"color:#000000\">gridspec <\/span><span style=\"color:#0077aa\">import<\/span><span style=\"color:#000000\"> GridSpec<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\">\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">GridSpec<\/span><span style=\"color:#999999\">(<\/span><span style=\"color:#000000\">nrows<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> ncols<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> figure<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#0077aa\">left<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#0077aa\">right<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> bottom<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#0077aa\">top<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> wspace<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> hspace<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> width_ratios<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> height_ratios<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> w_pad<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> h_pad<\/span><span style=\"color:#9a6e3a\">&#061;<\/span><span style=\"color:#000000\">None<\/span><span style=\"color:#999999\">)<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\">\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u53c2\u6570&#xff1a;nrows: <\/span><span style=\"color:#0077aa\">int<\/span><span style=\"color:#000000\">\u5b50\u56fe\u7f51\u683c\u7684\u884c\u6570\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ncols: <\/span><span style=\"color:#0077aa\">int<\/span><span style=\"color:#000000\">\u5b50\u56fe\u7f51\u683c\u7684\u5217\u6570\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0figure: matplotlib<\/span><span style=\"color:#999999\">.<\/span><span style=\"color:#000000\">figure<\/span><span style=\"color:#999999\">.<\/span><span style=\"color:#000000\">Figure<\/span><span style=\"color:#999999\">,<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0optional<\/span><span style=\"color:#999999\">,<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#0077aa\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0default<\/span><span style=\"color:#000000\">: None<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u6307\u5b9a\u7684\u56fe\u5f62\u5bf9\u8c61\u3002\u5982\u679c\u672a\u63d0\u4f9b&#xff0c;\u5219\u9ed8\u8ba4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u56fe\u5f62\u5bf9\u8c61\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#0077aa\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0left<\/span><span style=\"color:#000000\">: <\/span><span style=\"color:#0077aa\">float<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> optional<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#0077aa\">default<\/span><span style=\"color:#000000\">: None\u5b50\u56fe\u7f51\u683c\u5de6\u4fa7\u7684\u76f8\u5bf9\u4f4d\u7f6e&#xff08;<\/span><span style=\"color:#990055\">0<\/span><span style=\"color:#000000\"> \u5230 <\/span><span style=\"color:#990055\">1<\/span><span style=\"color:#000000\"> \u7684\u6bd4\u4f8b&#xff09;\u3002\u5982\u679c\u672a\u6307\u5b9a&#xff0c;\u5219\u4f7f\u7528\u9ed8\u8ba4\u7684\u5de6\u8fb9\u754c\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#0077aa\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0right<\/span><span style=\"color:#000000\">: <\/span><span style=\"color:#0077aa\">float<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> optional<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#0077aa\">default<\/span><span style=\"color:#000000\">: None\u5b50\u56fe\u7f51\u683c\u53f3\u4fa7\u7684\u76f8\u5bf9\u4f4d\u7f6e&#xff08;<\/span><span style=\"color:#990055\">0<\/span><span style=\"color:#000000\"> \u5230 <\/span><span style=\"color:#990055\">1<\/span><span style=\"color:#000000\"> \u7684\u6bd4\u4f8b&#xff09;\u3002\u5982\u679c\u672a\u6307\u5b9a&#xff0c;\u5219\u4f7f\u7528\u9ed8\u8ba4\u7684\u53f3\u8fb9\u754c\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0bottom: <\/span><span style=\"color:#0077aa\">float<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> optional<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#0077aa\">default<\/span><span style=\"color:#000000\">: None\u5b50\u56fe\u7f51\u683c\u5e95\u90e8\u7684\u76f8\u5bf9\u4f4d\u7f6e&#xff08;<\/span><span style=\"color:#990055\">0<\/span><span style=\"color:#000000\"> \u5230 <\/span><span style=\"color:#990055\">1<\/span><span style=\"color:#000000\"> \u7684\u6bd4\u4f8b&#xff09;\u3002\u5982\u679c\u672a\u6307\u5b9a&#xff0c;\u5219\u4f7f\u7528\u9ed8\u8ba4\u7684\u5e95\u8fb9\u754c\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#0077aa\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0top<\/span><span style=\"color:#000000\">: <\/span><span style=\"color:#0077aa\">float<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> optional<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#0077aa\">default<\/span><span style=\"color:#000000\">: None\u5b50\u56fe\u7f51\u683c\u9876\u90e8\u7684\u76f8\u5bf9\u4f4d\u7f6e&#xff08;<\/span><span style=\"color:#990055\">0<\/span><span style=\"color:#000000\"> \u5230 <\/span><span style=\"color:#990055\">1<\/span><span style=\"color:#000000\"> \u7684\u6bd4\u4f8b&#xff09;\u3002\u5982\u679c\u672a\u6307\u5b9a&#xff0c;\u5219\u4f7f\u7528\u9ed8\u8ba4\u7684\u9876\u8fb9\u754c\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0wspace: <\/span><span style=\"color:#0077aa\">float<\/span> <span style=\"color:#9a6e3a\">or<\/span><span style=\"color:#000000\"> None<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> optional<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#0077aa\">default<\/span><span style=\"color:#000000\">: None\u5b50\u56fe\u4e4b\u95f4\u7684\u6c34\u5e73\u95f4\u8ddd&#xff08;\u4ee5\u82f1\u5bf8\u4e3a\u5355\u4f4d&#xff09;\u6216\u4f5c\u4e3a\u5b50\u56fe\u5bbd\u5ea6\u7684\u6bd4\u4f8b\u3002\u5982\u679c\u672a\u6307\u5b9a&#xff0c;\u5219\u4f7f\u7528\u9ed8\u8ba4\u7684\u95f4\u8ddd\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0hspace: <\/span><span style=\"color:#0077aa\">float<\/span> <span style=\"color:#9a6e3a\">or<\/span><span style=\"color:#000000\"> None<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> optional<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#0077aa\">default<\/span><span style=\"color:#000000\">: None\u5b50\u56fe\u4e4b\u95f4\u7684\u5782\u76f4\u95f4\u8ddd&#xff08;\u4ee5\u82f1\u5bf8\u4e3a\u5355\u4f4d&#xff09;\u6216\u4f5c\u4e3a\u5b50\u56fe\u9ad8\u5ea6\u7684\u6bd4\u4f8b\u3002\u5982\u679c\u672a\u6307\u5b9a&#xff0c;\u5219\u4f7f\u7528\u9ed8\u8ba4\u7684\u95f4\u8ddd\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0width_ratios: list <\/span><span style=\"color:#0077aa\">of<\/span><span style=\"color:#000000\"> floats<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> optional<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#0077aa\">default<\/span><span style=\"color:#000000\">: None<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u6307\u5b9a\u6bcf\u4e00\u5217\u7684\u5bbd\u5ea6\u6bd4\u4f8b\u3002\u5982\u679c\u6307\u5b9a&#xff0c;\u5219 ncols \u5fc5\u987b\u4e0e\u5217\u8868\u957f\u5ea6\u5339\u914d\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0height_ratios: list <\/span><span style=\"color:#0077aa\">of<\/span><span style=\"color:#000000\"> floats<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> optional<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#0077aa\">default<\/span><span style=\"color:#000000\">: None<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u6307\u5b9a\u6bcf\u4e00\u884c\u7684\u9ad8\u5ea6\u6bd4\u4f8b\u3002\u5982\u679c\u6307\u5b9a&#xff0c;\u5219 nrows \u5fc5\u987b\u4e0e\u5217\u8868\u957f\u5ea6\u5339\u914d\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0w_pad: <\/span><span style=\"color:#0077aa\">float<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> optional<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#0077aa\">default<\/span><span style=\"color:#000000\">: None\u5b50\u56fe\u4e4b\u95f4\u7684\u6c34\u5e73\u586b\u5145&#xff08;\u4ee5\u82f1\u5bf8\u4e3a\u5355\u4f4d&#xff09;\u3002\u5982\u679c\u672a\u6307\u5b9a&#xff0c;\u5219\u4f7f\u7528\u9ed8\u8ba4\u7684\u586b\u5145\u3002<\/span><\/p>\n<p style=\"margin-left:0;margin-right:0;text-align:justify\"><span style=\"color:#000000\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0h_pad: <\/span><span style=\"color:#0077aa\">float<\/span><span style=\"color:#999999\">,<\/span><span style=\"color:#000000\"> optional<\/span><span style=\"color:#999999\">,<\/span> <span style=\"color:#0077aa\">default<\/span><span style=\"color:#000000\">: None\u5b50\u56fe\u4e4b\u95f4\u7684\u5782\u76f4\u586b\u5145&#xff08;\u4ee5\u82f1\u5bf8\u4e3a\u5355\u4f4d&#xff09;\u3002\u5982\u679c\u672a\u6307\u5b9a&#xff0c;\u5219\u4f7f\u7528\u9ed8\u8ba4\u7684\u586b\u5145\u3002<\/span><\/p>\n<p>import matplotlib.pyplot as plt<br \/>\nimport numpy as np<br \/>\nfrom matplotlib.gridspec import GridSpec<br \/>\n# import matplotlib.gridspec as gs<br \/>\nfig &#061; plt.figure()<\/p>\n<p># \u6dfb\u52a0\u5b50\u56fe\u7f51\u683c<br \/>\ngs &#061; GridSpec(2, 3)<br \/>\n# \u5728\u7b2c\u4e00\u884c\u6dfb\u52a0\u4e09\u4e2a\u5b50\u56fe<br \/>\nfig.add_subplot(gs[0, 0])<br \/>\nfig.add_subplot(gs[0, 1])<br \/>\nfig.add_subplot(gs[0, 2])<br \/>\n# \u5728\u7b2c\u4e8c\u884c\u6dfb\u52a0\u4e00\u4e2a\u5b50\u56fe<br \/>\nfig.add_subplot(gs[1, :])<\/p>\n<p>plt.show()<\/p>\n<\/p>\n<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb248\u6b21\uff0c\u70b9\u8d5e6\u6b21\uff0c\u6536\u85cf3\u6b21\u3002\u62b1\u6028\u8eab\u5904\u9ed1\u6697\uff0c\u4e0d\u5982\u63d0\u706f\u524d\u884c\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[2468,81,190],"topic":[],"class_list":["post-53714","post","type-post","status-publish","format-standard","hentry","category-server","tag-matplotlib","tag-python","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5c0f\u6770python\u9ad8\u7ea7\uff08four day\uff09\u2014\u2014matplotlib\u5e93 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/53714.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5c0f\u6770python\u9ad8\u7ea7\uff08four day\uff09\u2014\u2014matplotlib\u5e93 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb248\u6b21\uff0c\u70b9\u8d5e6\u6b21\uff0c\u6536\u85cf3\u6b21\u3002\u62b1\u6028\u8eab\u5904\u9ed1\u6697\uff0c\u4e0d\u5982\u63d0\u706f\u524d\u884c\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/53714.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-12T08:19:59+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/53714.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/53714.html\",\"name\":\"\u5c0f\u6770python\u9ad8\u7ea7\uff08four day\uff09\u2014\u2014matplotlib\u5e93 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-12T08:19:59+00:00\",\"dateModified\":\"2025-08-12T08:19:59+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/53714.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/53714.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/53714.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5c0f\u6770python\u9ad8\u7ea7\uff08four day\uff09\u2014\u2014matplotlib\u5e93\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u5c0f\u6770python\u9ad8\u7ea7\uff08four day\uff09\u2014\u2014matplotlib\u5e93 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/53714.html","og_locale":"zh_CN","og_type":"article","og_title":"\u5c0f\u6770python\u9ad8\u7ea7\uff08four day\uff09\u2014\u2014matplotlib\u5e93 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb248\u6b21\uff0c\u70b9\u8d5e6\u6b21\uff0c\u6536\u85cf3\u6b21\u3002\u62b1\u6028\u8eab\u5904\u9ed1\u6697\uff0c\u4e0d\u5982\u63d0\u706f\u524d\u884c\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/53714.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-12T08:19:59+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/53714.html","url":"https:\/\/www.wsisp.com\/helps\/53714.html","name":"\u5c0f\u6770python\u9ad8\u7ea7\uff08four day\uff09\u2014\u2014matplotlib\u5e93 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-12T08:19:59+00:00","dateModified":"2025-08-12T08:19:59+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/53714.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/53714.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/53714.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u5c0f\u6770python\u9ad8\u7ea7\uff08four day\uff09\u2014\u2014matplotlib\u5e93"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/53714","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=53714"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/53714\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=53714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=53714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=53714"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=53714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}