{"id":975116,"date":"2024-12-27T06:10:39","date_gmt":"2024-12-26T22:10:39","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/975116.html"},"modified":"2024-12-27T06:10:42","modified_gmt":"2024-12-26T22:10:42","slug":"python%e7%bb%98%e5%9b%be%e5%a6%82%e4%bd%95%e7%bc%a9%e6%94%be%e5%9d%90%e6%a0%87","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/975116.html","title":{"rendered":"python\u7ed8\u56fe\u5982\u4f55\u7f29\u653e\u5750\u6807"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24200516\/28277a70-7e43-46d3-82eb-3f5edd84a8f6.webp\" alt=\"python\u7ed8\u56fe\u5982\u4f55\u7f29\u653e\u5750\u6807\" \/><\/p>\n<p><p> \u5f00\u5934\u6bb5\u843d\uff1a<br \/>\u5728Python\u4e2d\u7ed8\u56fe\u65f6\u7f29\u653e\u5750\u6807\uff0c\u53ef\u4ee5\u901a\u8fc7<strong>\u8c03\u6574\u5750\u6807\u8f74\u8303\u56f4\u3001\u4f7f\u7528\u7f29\u653e\u529f\u80fd\u7684\u5e93\u3001\u4fee\u6539\u56fe\u5f62\u5c3a\u5bf8\u3001\u4ea4\u4e92\u5f0f\u7f29\u653e<\/strong>\u7b49\u65b9\u6cd5\u5b9e\u73b0\u3002\u5176\u4e2d\uff0c\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u8c03\u6574\u5750\u6807\u8f74\u8303\u56f4\uff0c\u901a\u8fc7\u8bbe\u5b9a\u8f74\u7684\u4e0a\u4e0b\u9650\u6765\u63a7\u5236\u7f29\u653e\u6bd4\u4f8b\u3002\u8fd9\u79cd\u65b9\u6cd5\u7b80\u5355\u76f4\u63a5\uff0c\u9002\u7528\u4e8e\u5927\u591a\u6570\u9759\u6001\u56fe\u7684\u7f29\u653e\u9700\u6c42\u3002\u4f8b\u5982\uff0c\u4f7f\u7528Matplotlib\u5e93\u53ef\u4ee5\u901a\u8fc7<code>set_xlim()<\/code>\u548c<code>set_ylim()<\/code>\u51fd\u6570\u6765\u8bbe\u7f6ex\u8f74\u548cy\u8f74\u7684\u8303\u56f4\uff0c\u4ece\u800c\u5b9e\u73b0\u5750\u6807\u7684\u7f29\u653e\u3002\u8fd9\u4e2a\u65b9\u6cd5\u4e0d\u4ec5\u53ef\u4ee5\u81ea\u5b9a\u4e49\u663e\u793a\u7684\u6570\u636e\u8303\u56f4\uff0c\u8fd8\u80fd\u6709\u6548\u63d0\u5347\u56fe\u5f62\u7684\u53ef\u8bfb\u6027\u548c\u7f8e\u89c2\u5ea6\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u8c03\u6574\u5750\u6807\u8f74\u8303\u56f4<\/p>\n<\/p>\n<p><p>\u8c03\u6574\u5750\u6807\u8f74\u8303\u56f4\u662f\u4e00\u79cd\u6700\u5e38\u7528\u7684\u7f29\u653e\u65b9\u6cd5\uff0c\u5b83\u901a\u8fc7\u8bbe\u5b9a\u5750\u6807\u8f74\u7684\u4e0a\u4e0b\u9650\u6765\u5b9e\u73b0\u5bf9\u56fe\u5f62\u7684\u7f29\u653e\u3002\u8fd9\u4e2a\u65b9\u6cd5\u901a\u5e38\u7528\u4e8e\u9759\u6001\u56fe\u3002<\/p>\n<\/p>\n<p><p>1.1 \u4f7f\u7528Matplotlib\u5e93\u8fdb\u884c\u8f74\u8303\u56f4\u8c03\u6574<\/p>\n<\/p>\n<p><p>Matplotlib\u662fPython\u4e2d\u6700\u5e38\u7528\u7684\u7ed8\u56fe\u5e93\u4e4b\u4e00\uff0c\u8c03\u6574\u5750\u6807\u8f74\u8303\u56f4\u53ef\u4ee5\u901a\u8fc7\u5176\u63d0\u4f9b\u7684<code>set_xlim()<\/code>\u548c<code>set_ylim()<\/code>\u65b9\u6cd5\u5b9e\u73b0\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>x = [0, 1, 2, 3, 4, 5]<\/p>\n<p>y = [0, 1, 4, 9, 16, 25]<\/p>\n<p>plt.plot(x, y)<\/p>\n<p>plt.xlim(0, 5)  # \u8bbe\u7f6ex\u8f74\u8303\u56f4<\/p>\n<p>plt.ylim(0, 30)  # \u8bbe\u7f6ey\u8f74\u8303\u56f4<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u4ee3\u7801\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0cx\u8f74\u88ab\u9650\u5236\u57280\u52305\u4e4b\u95f4\uff0c\u800cy\u8f74\u5219\u88ab\u9650\u5236\u57280\u523030\u4e4b\u95f4\u3002\u8fd9\u79cd\u65b9\u5f0f\u975e\u5e38\u7b80\u5355\u4e14\u9ad8\u6548\u3002<\/p>\n<\/p>\n<p><p>1.2 \u4f7f\u7528Seaborn\u5e93\u8fdb\u884c\u8f74\u8303\u56f4\u8c03\u6574<\/p>\n<\/p>\n<p><p>Seaborn\u662f\u4e00\u4e2a\u57fa\u4e8eMatplotlib\u7684\u9ad8\u7ea7\u63a5\u53e3\uff0c\u9002\u7528\u4e8e\u7edf\u8ba1\u6570\u636e\u7684\u53ef\u89c6\u5316\u3002\u867d\u7136\u4e3b\u8981\u7528\u4e8e\u7edf\u8ba1\u56fe\u5f62\uff0c\u4f46\u540c\u6837\u53ef\u4ee5\u901a\u8fc7Matplotlib\u7684\u63a5\u53e3\u8bbe\u7f6e\u8f74\u8303\u56f4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import seaborn as sns<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<p>tips = sns.load_dataset(&quot;tips&quot;)<\/p>\n<p>sns.scatterplot(data=tips, x=&quot;total_bill&quot;, y=&quot;tip&quot;)<\/p>\n<p>plt.xlim(0, 60)  # \u8bbe\u7f6ex\u8f74\u8303\u56f4<\/p>\n<p>plt.ylim(0, 12)  # \u8bbe\u7f6ey\u8f74\u8303\u56f4<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528Seaborn\u7ed8\u5236\u4e86\u4e00\u4e2a\u6563\u70b9\u56fe\uff0c\u5e76\u901a\u8fc7Matplotlib\u7684\u65b9\u6cd5\u5bf9\u5750\u6807\u8f74\u8fdb\u884c\u4e86\u8303\u56f4\u9650\u5236\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528\u7f29\u653e\u529f\u80fd\u7684\u5e93<\/p>\n<\/p>\n<p><p>\u9664\u4e86\u76f4\u63a5\u8c03\u6574\u5750\u6807\u8f74\u8303\u56f4\uff0c\u8fd8\u6709\u4e00\u4e9bPython\u5e93\u63d0\u4f9b\u4e86\u66f4\u52a0\u7075\u6d3b\u7684\u7f29\u653e\u529f\u80fd\uff0c\u5c24\u5176\u662f\u5728\u9700\u8981\u4ea4\u4e92\u5f0f\u56fe\u5f62\u65f6\u3002<\/p>\n<\/p>\n<p><p>2.1 \u4f7f\u7528Bokeh\u5e93\u8fdb\u884c\u7f29\u653e<\/p>\n<\/p>\n<p><p>Bokeh\u662f\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u4ea4\u4e92\u5f0f\u53ef\u89c6\u5316\u5e93\uff0c\u7279\u522b\u9002\u5408\u5927\u89c4\u6a21\u6570\u636e\u7684\u7ed8\u56fe\u3002Bokeh\u63d0\u4f9b\u4e86\u5185\u7f6e\u7684\u5de5\u5177\u680f\uff0c\u5176\u4e2d\u5305\u62ec\u7f29\u653e\u5de5\u5177\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from bokeh.plotting import figure, show<\/p>\n<p>from bokeh.io import output_notebook<\/p>\n<p>output_notebook()<\/p>\n<p>x = [0, 1, 2, 3, 4, 5]<\/p>\n<p>y = [0, 1, 4, 9, 16, 25]<\/p>\n<p>p = figure(title=&quot;Simple line example&quot;, x_axis_label=&#39;x&#39;, y_axis_label=&#39;y&#39;, tools=&quot;pan,wheel_zoom,box_zoom,reset&quot;)<\/p>\n<p>p.line(x, y, legend_label=&quot;Line&quot;, line_width=2)<\/p>\n<p>show(p)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728Bokeh\u4e2d\uff0c\u901a\u8fc7<code>tools<\/code>\u53c2\u6570\u53ef\u4ee5\u6307\u5b9a\u9700\u8981\u7684\u5de5\u5177\uff0c\u6bd4\u5982<code>wheel_zoom<\/code>\u5c31\u53ef\u4ee5\u4f7f\u7528\u9f20\u6807\u6eda\u8f6e\u6765\u7f29\u653e\u56fe\u5f62\u3002<\/p>\n<\/p>\n<p><p>2.2 \u4f7f\u7528Plotly\u5e93\u8fdb\u884c\u7f29\u653e<\/p>\n<\/p>\n<p><p>Plotly\u662f\u53e6\u4e00\u4e2a\u975e\u5e38\u6d41\u884c\u7684\u4ea4\u4e92\u5f0f\u7ed8\u56fe\u5e93\uff0c\u7279\u522b\u662f\u5728Web\u5e94\u7528\u4e2d\u4f7f\u7528\u5e7f\u6cdb\u3002Plotly\u9ed8\u8ba4\u652f\u6301\u56fe\u5f62\u7f29\u653e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import plotly.express as px<\/p>\n<p>df = px.data.iris()<\/p>\n<p>fig = px.scatter(df, x=&quot;sepal_width&quot;, y=&quot;sepal_length&quot;)<\/p>\n<p>fig.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728Plotly\u4e2d\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7\u9f20\u6807\u62d6\u52a8\u6765\u7f29\u653e\u56fe\u5f62\uff0c\u4e14\u4e0d\u9700\u8981\u8fdb\u884c\u989d\u5916\u7684\u914d\u7f6e\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4fee\u6539\u56fe\u5f62\u5c3a\u5bf8<\/p>\n<\/p>\n<p><p>\u8c03\u6574\u56fe\u5f62\u5c3a\u5bf8\u4e5f\u662f\u4e00\u79cd\u5b9e\u73b0\u7f29\u653e\u7684\u624b\u6bb5\u3002\u901a\u8fc7\u6539\u53d8\u8f93\u51fa\u56fe\u5f62\u7684\u5927\u5c0f\uff0c\u53ef\u4ee5\u95f4\u63a5\u8fbe\u5230\u7f29\u653e\u7684\u6548\u679c\u3002<\/p>\n<\/p>\n<p><p>3.1 \u4fee\u6539Matplotlib\u56fe\u5f62\u5c3a\u5bf8<\/p>\n<\/p>\n<p><p>\u5728Matplotlib\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7<code>figure<\/code>\u51fd\u6570\u7684<code>figsize<\/code>\u53c2\u6570\u6765\u8bbe\u7f6e\u56fe\u5f62\u7684\u5927\u5c0f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>plt.figure(figsize=(10, 5))  # \u8bbe\u7f6e\u56fe\u5f62\u5927\u5c0f\u4e3a10x5\u82f1\u5bf8<\/p>\n<p>x = [0, 1, 2, 3, 4, 5]<\/p>\n<p>y = [0, 1, 4, 9, 16, 25]<\/p>\n<p>plt.plot(x, y)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8c03\u6574<code>figsize<\/code>\u53c2\u6570\uff0c\u53ef\u4ee5\u5728\u4fdd\u8bc1\u5750\u6807\u8f74\u8303\u56f4\u4e0d\u53d8\u7684\u60c5\u51b5\u4e0b\u7f29\u653e\u6574\u4e2a\u56fe\u5f62\u3002<\/p>\n<\/p>\n<p><p>3.2 \u4fee\u6539Seaborn\u56fe\u5f62\u5c3a\u5bf8<\/p>\n<\/p>\n<p><p>\u540c\u6837\u5730\uff0c\u5728Seaborn\u4e2d\u4e5f\u53ef\u4ee5\u901a\u8fc7Matplotlib\u7684<code>figure<\/code>\u51fd\u6570\u6765\u8c03\u6574\u56fe\u5f62\u5c3a\u5bf8\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import seaborn as sns<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<p>plt.figure(figsize=(12, 6))  # \u8bbe\u7f6e\u56fe\u5f62\u5927\u5c0f\u4e3a12x6\u82f1\u5bf8<\/p>\n<p>tips = sns.load_dataset(&quot;tips&quot;)<\/p>\n<p>sns.scatterplot(data=tips, x=&quot;total_bill&quot;, y=&quot;tip&quot;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>Seaborn\u4e2d\uff0c<code>figsize<\/code>\u7684\u8c03\u6574\u540c\u6837\u53ef\u4ee5\u5f71\u54cd\u5230\u6700\u7ec8\u8f93\u51fa\u56fe\u5f62\u7684\u5c3a\u5bf8\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u4ea4\u4e92\u5f0f\u7f29\u653e<\/p>\n<\/p>\n<p><p>\u5bf9\u4e8e\u9700\u8981\u52a8\u6001\u4ea4\u4e92\u7684\u573a\u666f\uff0c\u4ea4\u4e92\u5f0f\u7f29\u653e\u662f\u975e\u5e38\u6709\u7528\u7684\u529f\u80fd\u3002\u901a\u8fc7\u4ea4\u4e92\u5f0f\u7f29\u653e\uff0c\u7528\u6237\u53ef\u4ee5\u81ea\u7531\u653e\u5927\u6216\u7f29\u5c0f\u7279\u5b9a\u533a\u57df\u3002<\/p>\n<\/p>\n<p><p>4.1 \u4f7f\u7528ipywidgets\u5b9e\u73b0\u4ea4\u4e92\u5f0f\u7f29\u653e<\/p>\n<\/p>\n<p><p>ipywidgets\u662f\u4e00\u4e2a\u7528\u4e8e\u521b\u5efa\u4ea4\u4e92\u5f0f\u5c0f\u90e8\u4ef6\u7684\u5e93\uff0c\u53ef\u4ee5\u4e0eJupyter Notebook\u7ed3\u5408\u4f7f\u7528\uff0c\u63d0\u4f9b\u4ea4\u4e92\u5f0f\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import numpy as np<\/p>\n<p>from ipywidgets import interact<\/p>\n<p>x = np.linspace(0, 10, 100)<\/p>\n<p>y = np.sin(x)<\/p>\n<p>def plot_func(xmin, xmax):<\/p>\n<p>    plt.figure(figsize=(8, 4))<\/p>\n<p>    plt.plot(x, y)<\/p>\n<p>    plt.xlim(xmin, xmax)<\/p>\n<p>    plt.show()<\/p>\n<p>interact(plot_func, xmin=(0, 10, 0.1), xmax=(0, 10, 0.1))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7<code>interact<\/code>\u51fd\u6570\uff0c\u7528\u6237\u53ef\u4ee5\u62d6\u52a8\u6ed1\u5757\u6765\u6539\u53d8\u663e\u793a\u7684x\u8f74\u8303\u56f4\uff0c\u5b9e\u73b0\u4ea4\u4e92\u5f0f\u7f29\u653e\u3002<\/p>\n<\/p>\n<p><p>4.2 \u4f7f\u7528Holoviews\u8fdb\u884c\u4ea4\u4e92\u5f0f\u7f29\u653e<\/p>\n<\/p>\n<p><p>Holoviews\u662f\u4e00\u4e2a\u7528\u4e8e\u6570\u636e\u53ef\u89c6\u5316\u7684\u9ad8\u5c42\u63a5\u53e3\uff0c\u652f\u6301\u4ea4\u4e92\u5f0f\u529f\u80fd\uff0c\u5e76\u4e0eBokeh\u7ed3\u5408\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import holoviews as hv<\/p>\n<p>import numpy as np<\/p>\n<p>hv.extension(&#39;bokeh&#39;)<\/p>\n<p>x = np.linspace(0, 10, 100)<\/p>\n<p>y = np.sin(x)<\/p>\n<p>curve = hv.Curve((x, y))<\/p>\n<p>curve.opts(width=800, tools=[&#39;hover&#39;, &#39;box_zoom&#39;, &#39;wheel_zoom&#39;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728Holoviews\u4e2d\uff0c\u76f4\u63a5\u901a\u8fc7<code>opts<\/code>\u9009\u9879\u53ef\u4ee5\u914d\u7f6e\u4ea4\u4e92\u5de5\u5177\uff0c\u4f8b\u5982<code>box_zoom<\/code>\u548c<code>wheel_zoom<\/code>\uff0c\u4ece\u800c\u5b9e\u73b0\u4ea4\u4e92\u5f0f\u7f29\u653e\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u603b\u7ed3\u4e0e\u5efa\u8bae<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\u5b9e\u73b0\u7ed8\u56fe\u7f29\u653e\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff0c\u5177\u4f53\u9009\u62e9\u53d6\u51b3\u4e8e\u4f7f\u7528\u573a\u666f\u548c\u9700\u6c42\u3002<\/p>\n<\/p>\n<ul>\n<li><strong>\u9759\u6001\u56fe<\/strong>\uff1a\u5982\u679c\u53ea\u662f\u9700\u8981\u7b80\u5355\u7684\u9759\u6001\u56fe\uff0c\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574\u5750\u6807\u8f74\u8303\u56f4\u6765\u5b9e\u73b0\u3002<\/li>\n<li><strong>\u4ea4\u4e92\u5f0f\u56fe<\/strong>\uff1a\u5bf9\u4e8e\u9700\u8981\u7528\u6237\u4ea4\u4e92\u7684\u573a\u666f\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528Bokeh\u6216Plotly\u7b49\u4ea4\u4e92\u5f0f\u5e93\u3002<\/li>\n<li><strong>\u5927\u89c4\u6a21\u6570\u636e<\/strong>\uff1a\u5728\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u65f6\uff0c\u9009\u62e9\u652f\u6301\u4ea4\u4e92\u4e14\u9ad8\u6027\u80fd\u7684\u5e93\uff08\u5982Holoviews\u4e0eBokeh\u7ed3\u5408\uff09\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\u3002<\/li>\n<\/ul>\n<p><p>\u65e0\u8bba\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\uff0c\u4e86\u89e3\u6bcf\u79cd\u65b9\u6cd5\u7684\u4f18\u7f3a\u70b9\uff0c\u5e76\u6839\u636e\u5b9e\u9645\u9700\u6c42\u6765\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\u548c\u6280\u672f\uff0c\u5c06\u6709\u52a9\u4e8e\u66f4\u6709\u6548\u5730\u5b9e\u73b0\u76ee\u6807\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u7ed8\u56fe\u4e2d\u5b9e\u73b0\u5750\u6807\u7684\u7f29\u653e\u529f\u80fd\uff1f<\/strong><br \/>\u5728Python\u7ed8\u56fe\u4e2d\uff0c\u4f7f\u7528Matplotlib\u5e93\u53ef\u4ee5\u65b9\u4fbf\u5730\u5b9e\u73b0\u5750\u6807\u7684\u7f29\u653e\u3002\u901a\u8fc7<code>xlim<\/code>\u548c<code>ylim<\/code>\u51fd\u6570\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u5750\u6807\u8f74\u7684\u8303\u56f4\u6765\u5b9e\u73b0\u7f29\u653e\u6548\u679c\u3002\u4f8b\u5982\uff0c<code>plt.xlim(0, 10)<\/code>\u5c06X\u8f74\u7684\u8303\u56f4\u8bbe\u7f6e\u4e3a0\u523010\uff0c<code>plt.ylim(0, 20)<\/code>\u5c06Y\u8f74\u7684\u8303\u56f4\u8bbe\u7f6e\u4e3a0\u523020\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u7528\u6237\u53ef\u4ee5\u7075\u6d3b\u5730\u8c03\u6574\u53ef\u89c6\u5316\u7684\u7ec6\u8282\u3002<\/p>\n<p><strong>\u5728\u4f7f\u7528Matplotlib\u7ed8\u56fe\u65f6\uff0c\u5982\u4f55\u81ea\u5b9a\u4e49\u7f29\u653e\u6bd4\u4f8b\uff1f<\/strong><br \/>\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574\u5750\u6807\u8f74\u7684\u9650\u5236\u548c\u6b65\u957f\u6765\u81ea\u5b9a\u4e49\u7f29\u653e\u6bd4\u4f8b\u3002\u4f7f\u7528<code>set_xticks()<\/code>\u548c<code>set_yticks()<\/code>\u65b9\u6cd5\uff0c\u53ef\u4ee5\u63a7\u5236\u5750\u6807\u8f74\u4e0a\u523b\u5ea6\u7684\u663e\u793a\u4f4d\u7f6e\uff0c\u4ece\u800c\u5b9e\u73b0\u66f4\u7cbe\u786e\u7684\u7f29\u653e\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5b9a\u4e49\u523b\u5ea6\u4e3a<code>np.arange(0, 10, 0.5)<\/code>\u6765\u4f7fX\u8f74\u7684\u523b\u5ea6\u6bcf0.5\u4e2a\u5355\u4f4d\u663e\u793a\u4e00\u6b21\uff0c\u8fd9\u6837\u4fbf\u4e8e\u89c2\u5bdf\u6570\u636e\u53d8\u5316\u3002<\/p>\n<p><strong>\u5982\u679c\u6211\u60f3\u5728\u4ea4\u4e92\u5f0f\u7ed8\u56fe\u4e2d\u5b9e\u73b0\u52a8\u6001\u7f29\u653e\uff0c\u8be5\u600e\u4e48\u505a\uff1f<\/strong><br \/>\u4f7f\u7528Matplotlib\u7684\u4ea4\u4e92\u5f0f\u6a21\u5f0f\uff0c\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u9f20\u6807\u6eda\u8f6e\u6216\u8005\u624b\u52a8\u62d6\u52a8\u9f20\u6807\u6765\u52a8\u6001\u7f29\u653e\u56fe\u5f62\u3002\u901a\u8fc7\u8bbe\u7f6e<code>plt.ion()<\/code>\u542f\u7528\u4ea4\u4e92\u6a21\u5f0f\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u56fe\u5f62\u7a97\u53e3\u4e2d\u76f4\u63a5\u8fdb\u884c\u7f29\u653e\u64cd\u4f5c\u3002\u6b64\u5916\uff0c\u7ed3\u5408<code>mplcursors<\/code>\u5e93\uff0c\u8fd8\u53ef\u4ee5\u5b9e\u73b0\u66f4\u9ad8\u7ea7\u7684\u4ea4\u4e92\u529f\u80fd\uff0c\u6bd4\u5982\u5728\u7f29\u653e\u65f6\u663e\u793a\u6570\u636e\u70b9\u7684\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5f00\u5934\u6bb5\u843d\uff1a\u5728Python\u4e2d\u7ed8\u56fe\u65f6\u7f29\u653e\u5750\u6807\uff0c\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574\u5750\u6807\u8f74\u8303\u56f4\u3001\u4f7f\u7528\u7f29\u653e\u529f\u80fd\u7684\u5e93\u3001\u4fee\u6539\u56fe\u5f62\u5c3a\u5bf8\u3001\u4ea4\u4e92\u5f0f\u7f29\u653e\u7b49 [&hellip;]","protected":false},"author":3,"featured_media":975124,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/975116"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=975116"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/975116\/revisions"}],"predecessor-version":[{"id":975130,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/975116\/revisions\/975130"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/975124"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=975116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=975116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=975116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}