{"id":1173467,"date":"2025-01-15T17:03:34","date_gmt":"2025-01-15T09:03:34","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1173467.html"},"modified":"2025-01-15T17:03:37","modified_gmt":"2025-01-15T09:03:37","slug":"python%e5%9b%be%e5%a6%82%e4%bd%95%e5%af%bc%e5%87%ba%e7%94%bb%e5%9b%be%e6%95%b0%e6%8d%ae","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1173467.html","title":{"rendered":"python\u56fe\u5982\u4f55\u5bfc\u51fa\u753b\u56fe\u6570\u636e"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/26075245\/79d10671-4641-4901-8e5a-a96cd7f426ee.webp\" alt=\"python\u56fe\u5982\u4f55\u5bfc\u51fa\u753b\u56fe\u6570\u636e\" \/><\/p>\n<p><p> <strong>Python\u56fe\u5982\u4f55\u5bfc\u51fa\u753b\u56fe\u6570\u636e\uff1a<\/strong> \u4f7f\u7528 Matplotlib \u5e93\u3001\u4f7f\u7528 pandas \u5e93\u3001\u4f7f\u7528 seaborn \u5e93\u3002 <strong>\u4f7f\u7528 Matplotlib \u5e93<\/strong> \u662f\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002Matplotlib \u662f Python \u4e2d\u6700\u6d41\u884c\u7684\u7ed8\u56fe\u5e93\u4e4b\u4e00\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u6765\u521b\u5efa\u5404\u79cd\u7c7b\u578b\u7684\u56fe\u5f62\uff0c\u5e76\u4e14\u53ef\u4ee5\u65b9\u4fbf\u5730\u5bfc\u51fa\u56fe\u5f62\u6570\u636e\u3002\u901a\u8fc7 Matplotlib\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u7ed8\u5236\u7684\u56fe\u5f62\u6570\u636e\u4fdd\u5b58\u4e3a\u591a\u79cd\u683c\u5f0f\uff0c\u5305\u62ec PNG\u3001PDF\u3001SVG \u7b49\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528 Matplotlib \u5e93<\/h3>\n<\/p>\n<p><p>Matplotlib \u662f Python \u4e2d\u6700\u5e38\u7528\u7684\u7ed8\u56fe\u5e93\u4e4b\u4e00\u3002\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u6765\u521b\u5efa\u5404\u79cd\u7c7b\u578b\u7684\u56fe\u5f62\uff0c\u5e76\u4e14\u53ef\u4ee5\u65b9\u4fbf\u5730\u5bfc\u51fa\u56fe\u5f62\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5bfc\u51fa\u56fe\u5f62\u6570\u636e\u5230 CSV \u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u5728\u4f7f\u7528 Matplotlib \u7ed8\u56fe\u65f6\uff0c\u901a\u5e38\u6211\u4eec\u4f7f\u7528 <code>plot<\/code>\u3001<code>scatter<\/code>\u3001<code>bar<\/code> \u7b49\u51fd\u6570\u6765\u521b\u5efa\u56fe\u5f62\u3002\u8fd9\u4e9b\u51fd\u6570\u4f1a\u751f\u6210\u4e00\u4e2a <code>Axes<\/code> \u5bf9\u8c61\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95ee\u8be5\u5bf9\u8c61\u6765\u83b7\u53d6\u56fe\u5f62\u6570\u636e\uff0c\u5e76\u5c06\u5176\u5bfc\u51fa\u4e3a CSV \u6587\u4ef6\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>import csv<\/p>\n<h2><strong>\u751f\u6210\u793a\u4f8b\u6570\u636e<\/strong><\/h2>\n<p>x = np.linspace(0, 10, 100)<\/p>\n<p>y = np.sin(x)<\/p>\n<h2><strong>\u521b\u5efa\u56fe\u5f62<\/strong><\/h2>\n<p>fig, ax = plt.subplots()<\/p>\n<p>ax.plot(x, y)<\/p>\n<h2><strong>\u83b7\u53d6\u56fe\u5f62\u6570\u636e<\/strong><\/h2>\n<p>lines = ax.get_lines()<\/p>\n<p>line = lines[0]<\/p>\n<p>data = line.get_xydata()<\/p>\n<h2><strong>\u5c06\u6570\u636e\u5bfc\u51fa\u4e3a CSV \u6587\u4ef6<\/strong><\/h2>\n<p>with open(&#39;plot_data.csv&#39;, &#39;w&#39;, newline=&#39;&#39;) as csvfile:<\/p>\n<p>    csvwriter = csv.writer(csvfile)<\/p>\n<p>    csvwriter.writerow([&#39;x&#39;, &#39;y&#39;])<\/p>\n<p>    csvwriter.writerows(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u5bfc\u51fa\u56fe\u5f62\u6570\u636e\u5230 Excel \u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528 <code>pandas<\/code> \u5e93\u5c06\u56fe\u5f62\u6570\u636e\u5bfc\u51fa\u4e3a Excel \u6587\u4ef6\u3002<code>pandas<\/code> \u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u5e93\uff0c\u5177\u6709\u65b9\u4fbf\u7684 Excel \u5bfc\u51fa\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>import pandas as pd<\/p>\n<h2><strong>\u751f\u6210\u793a\u4f8b\u6570\u636e<\/strong><\/h2>\n<p>x = np.linspace(0, 10, 100)<\/p>\n<p>y = np.sin(x)<\/p>\n<h2><strong>\u521b\u5efa\u56fe\u5f62<\/strong><\/h2>\n<p>fig, ax = plt.subplots()<\/p>\n<p>ax.plot(x, y)<\/p>\n<h2><strong>\u83b7\u53d6\u56fe\u5f62\u6570\u636e<\/strong><\/h2>\n<p>lines = ax.get_lines()<\/p>\n<p>line = lines[0]<\/p>\n<p>data = line.get_xydata()<\/p>\n<h2><strong>\u521b\u5efa DataFrame<\/strong><\/h2>\n<p>df = pd.DataFrame(data, columns=[&#39;x&#39;, &#39;y&#39;])<\/p>\n<h2><strong>\u5c06\u6570\u636e\u5bfc\u51fa\u4e3a Excel \u6587\u4ef6<\/strong><\/h2>\n<p>df.to_excel(&#39;plot_data.xlsx&#39;, index=False)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528 Pandas \u5e93<\/h3>\n<\/p>\n<p><p>Pandas \u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u5e93\uff0c\u5b83\u4e0d\u4ec5\u53ef\u4ee5\u5904\u7406\u6570\u636e\uff0c\u8fd8\u53ef\u4ee5\u65b9\u4fbf\u5730\u4e0e Matplotlib \u96c6\u6210\uff0c\u751f\u6210\u56fe\u5f62\u5e76\u5bfc\u51fa\u56fe\u5f62\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528 Pandas \u7ed8\u56fe\u5e76\u5bfc\u51fa\u6570\u636e<\/h4>\n<\/p>\n<p><p>Pandas \u63d0\u4f9b\u4e86\u76f4\u63a5\u7ed8\u56fe\u7684\u529f\u80fd\uff0c\u901a\u8fc7\u8c03\u7528 DataFrame \u6216 Series \u5bf9\u8c61\u7684 <code>plot<\/code> \u65b9\u6cd5\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u521b\u5efa\u56fe\u5f62\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u751f\u6210\u793a\u4f8b\u6570\u636e<\/strong><\/h2>\n<p>x = np.linspace(0, 10, 100)<\/p>\n<p>y = np.sin(x)<\/p>\n<h2><strong>\u521b\u5efa DataFrame<\/strong><\/h2>\n<p>df = pd.DataFrame({&#39;x&#39;: x, &#39;y&#39;: y})<\/p>\n<h2><strong>\u7ed8\u56fe<\/strong><\/h2>\n<p>ax = df.plot(x=&#39;x&#39;, y=&#39;y&#39;)<\/p>\n<h2><strong>\u5bfc\u51fa\u56fe\u5f62\u6570\u636e\u5230 CSV \u6587\u4ef6<\/strong><\/h2>\n<p>df.to_csv(&#39;plot_data.csv&#39;, index=False)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528 Pandas \u548c Matplotlib \u96c6\u6210<\/h4>\n<\/p>\n<p><p>\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528 Pandas \u548c Matplotlib \u96c6\u6210\uff0c\u521b\u5efa\u66f4\u590d\u6742\u7684\u56fe\u5f62\uff0c\u5e76\u5bfc\u51fa\u56fe\u5f62\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u751f\u6210\u793a\u4f8b\u6570\u636e<\/strong><\/h2>\n<p>x = np.linspace(0, 10, 100)<\/p>\n<p>y1 = np.sin(x)<\/p>\n<p>y2 = np.cos(x)<\/p>\n<h2><strong>\u521b\u5efa DataFrame<\/strong><\/h2>\n<p>df = pd.DataFrame({&#39;x&#39;: x, &#39;y1&#39;: y1, &#39;y2&#39;: y2})<\/p>\n<h2><strong>\u7ed8\u56fe<\/strong><\/h2>\n<p>fig, ax = plt.subplots()<\/p>\n<p>df.plot(x=&#39;x&#39;, y=&#39;y1&#39;, ax=ax, label=&#39;sin(x)&#39;)<\/p>\n<p>df.plot(x=&#39;x&#39;, y=&#39;y2&#39;, ax=ax, label=&#39;cos(x)&#39;)<\/p>\n<h2><strong>\u5bfc\u51fa\u56fe\u5f62\u6570\u636e\u5230 CSV \u6587\u4ef6<\/strong><\/h2>\n<p>df.to_csv(&#39;plot_data.csv&#39;, index=False)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528 Seaborn \u5e93<\/h3>\n<\/p>\n<p><p>Seaborn \u662f\u57fa\u4e8e Matplotlib \u7684\u9ad8\u7ea7\u7ed8\u56fe\u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u66f4\u7b80\u6d01\u7684 API \u548c\u66f4\u7f8e\u89c2\u7684\u9ed8\u8ba4\u6837\u5f0f\u3002Seaborn \u4e5f\u53ef\u4ee5\u65b9\u4fbf\u5730\u5bfc\u51fa\u56fe\u5f62\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528 Seaborn \u7ed8\u56fe\u5e76\u5bfc\u51fa\u6570\u636e<\/h4>\n<\/p>\n<p><p>Seaborn \u63d0\u4f9b\u4e86\u591a\u79cd\u7c7b\u578b\u7684\u56fe\u5f62\uff0c\u5982\u7ebf\u56fe\u3001\u6563\u70b9\u56fe\u3001\u6761\u5f62\u56fe\u7b49\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 Seaborn \u521b\u5efa\u56fe\u5f62\uff0c\u5e76\u5c06\u6570\u636e\u5bfc\u51fa\u4e3a CSV \u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import seaborn as sns<\/p>\n<p>import pandas as pd<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u751f\u6210\u793a\u4f8b\u6570\u636e<\/strong><\/h2>\n<p>x = np.linspace(0, 10, 100)<\/p>\n<p>y = np.sin(x)<\/p>\n<h2><strong>\u521b\u5efa DataFrame<\/strong><\/h2>\n<p>df = pd.DataFrame({&#39;x&#39;: x, &#39;y&#39;: y})<\/p>\n<h2><strong>\u7ed8\u56fe<\/strong><\/h2>\n<p>sns.lineplot(x=&#39;x&#39;, y=&#39;y&#39;, data=df)<\/p>\n<h2><strong>\u5bfc\u51fa\u56fe\u5f62\u6570\u636e\u5230 CSV \u6587\u4ef6<\/strong><\/h2>\n<p>df.to_csv(&#39;plot_data.csv&#39;, index=False)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528 Seaborn \u548c Matplotlib \u96c6\u6210<\/h4>\n<\/p>\n<p><p>\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528 Seaborn \u548c Matplotlib \u96c6\u6210\uff0c\u521b\u5efa\u66f4\u590d\u6742\u7684\u56fe\u5f62\uff0c\u5e76\u5bfc\u51fa\u56fe\u5f62\u6570\u636e\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>import pandas as pd<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u751f\u6210\u793a\u4f8b\u6570\u636e<\/strong><\/h2>\n<p>x = np.linspace(0, 10, 100)<\/p>\n<p>y1 = np.sin(x)<\/p>\n<p>y2 = np.cos(x)<\/p>\n<h2><strong>\u521b\u5efa DataFrame<\/strong><\/h2>\n<p>df = pd.DataFrame({&#39;x&#39;: x, &#39;y1&#39;: y1, &#39;y2&#39;: y2})<\/p>\n<h2><strong>\u7ed8\u56fe<\/strong><\/h2>\n<p>fig, ax = plt.subplots()<\/p>\n<p>sns.lineplot(x=&#39;x&#39;, y=&#39;y1&#39;, data=df, ax=ax, label=&#39;sin(x)&#39;)<\/p>\n<p>sns.lineplot(x=&#39;x&#39;, y=&#39;y2&#39;, data=df, ax=ax, label=&#39;cos(x)&#39;)<\/p>\n<h2><strong>\u5bfc\u51fa\u56fe\u5f62\u6570\u636e\u5230 CSV \u6587\u4ef6<\/strong><\/h2>\n<p>df.to_csv(&#39;plot_data.csv&#39;, index=False)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u5176\u4ed6\u7ed8\u56fe\u5e93<\/h3>\n<\/p>\n<p><p>\u9664\u4e86 Matplotlib\u3001Pandas \u548c Seaborn \u4e4b\u5916\uff0cPython \u8fd8\u6709\u8bb8\u591a\u5176\u4ed6\u7684\u7ed8\u56fe\u5e93\uff0c\u5982 Plotly\u3001Bokeh\u3001Alt<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>r \u7b49\u3002\u8fd9\u4e9b\u5e93\u4e5f\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u6765\u521b\u5efa\u548c\u5bfc\u51fa\u56fe\u5f62\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528 Plotly \u7ed8\u56fe\u5e76\u5bfc\u51fa\u6570\u636e<\/h4>\n<\/p>\n<p><p>Plotly \u662f\u4e00\u4e2a\u4ea4\u4e92\u5f0f\u7ed8\u56fe\u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u4ea4\u4e92\u529f\u80fd\u548c\u7f8e\u89c2\u7684\u56fe\u5f62\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 Plotly \u521b\u5efa\u56fe\u5f62\uff0c\u5e76\u5c06\u6570\u636e\u5bfc\u51fa\u4e3a CSV \u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import plotly.express as px<\/p>\n<p>import pandas as pd<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u751f\u6210\u793a\u4f8b\u6570\u636e<\/strong><\/h2>\n<p>x = np.linspace(0, 10, 100)<\/p>\n<p>y = np.sin(x)<\/p>\n<h2><strong>\u521b\u5efa DataFrame<\/strong><\/h2>\n<p>df = pd.DataFrame({&#39;x&#39;: x, &#39;y&#39;: y})<\/p>\n<h2><strong>\u7ed8\u56fe<\/strong><\/h2>\n<p>fig = px.line(df, x=&#39;x&#39;, y=&#39;y&#39;)<\/p>\n<h2><strong>\u5bfc\u51fa\u56fe\u5f62\u6570\u636e\u5230 CSV \u6587\u4ef6<\/strong><\/h2>\n<p>df.to_csv(&#39;plot_data.csv&#39;, index=False)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528 Bokeh \u7ed8\u56fe\u5e76\u5bfc\u51fa\u6570\u636e<\/h4>\n<\/p>\n<p><p>Bokeh \u662f\u4e00\u4e2a\u7528\u4e8e\u521b\u5efa\u4ea4\u4e92\u5f0f\u53ef\u89c6\u5316\u7684\u5e93\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 Bokeh \u521b\u5efa\u56fe\u5f62\uff0c\u5e76\u5c06\u6570\u636e\u5bfc\u51fa\u4e3a CSV \u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import bokeh.plotting as bkp<\/p>\n<p>import pandas as pd<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u751f\u6210\u793a\u4f8b\u6570\u636e<\/strong><\/h2>\n<p>x = np.linspace(0, 10, 100)<\/p>\n<p>y = np.sin(x)<\/p>\n<h2><strong>\u521b\u5efa DataFrame<\/strong><\/h2>\n<p>df = pd.DataFrame({&#39;x&#39;: x, &#39;y&#39;: y})<\/p>\n<h2><strong>\u7ed8\u56fe<\/strong><\/h2>\n<p>p = bkp.figure(title=&quot;sin(x)&quot;)<\/p>\n<p>p.line(x, y)<\/p>\n<h2><strong>\u5bfc\u51fa\u56fe\u5f62\u6570\u636e\u5230 CSV \u6587\u4ef6<\/strong><\/h2>\n<p>df.to_csv(&#39;plot_data.csv&#39;, index=False)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>bkp.show(p)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u4f7f\u7528 Altair \u7ed8\u56fe\u5e76\u5bfc\u51fa\u6570\u636e<\/h4>\n<\/p>\n<p><p>Altair \u662f\u4e00\u4e2a\u57fa\u4e8e Vega \u548c Vega-Lite \u7684\u58f0\u660e\u6027\u7edf\u8ba1\u53ef\u89c6\u5316\u5e93\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 Altair \u521b\u5efa\u56fe\u5f62\uff0c\u5e76\u5c06\u6570\u636e\u5bfc\u51fa\u4e3a CSV \u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import altair as alt<\/p>\n<p>import pandas as pd<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u751f\u6210\u793a\u4f8b\u6570\u636e<\/strong><\/h2>\n<p>x = np.linspace(0, 10, 100)<\/p>\n<p>y = np.sin(x)<\/p>\n<h2><strong>\u521b\u5efa DataFrame<\/strong><\/h2>\n<p>df = pd.DataFrame({&#39;x&#39;: x, &#39;y&#39;: y})<\/p>\n<h2><strong>\u7ed8\u56fe<\/strong><\/h2>\n<p>chart = alt.Chart(df).mark_line().encode(<\/p>\n<p>    x=&#39;x&#39;,<\/p>\n<p>    y=&#39;y&#39;<\/p>\n<p>)<\/p>\n<h2><strong>\u5bfc\u51fa\u56fe\u5f62\u6570\u636e\u5230 CSV \u6587\u4ef6<\/strong><\/h2>\n<p>df.to_csv(&#39;plot_data.csv&#39;, index=False)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u5f62<\/strong><\/h2>\n<p>chart.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728 Python \u4e2d\uff0c\u6709\u591a\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5bfc\u51fa\u56fe\u5f62\u6570\u636e\u3002<strong>\u4f7f\u7528 Matplotlib \u5e93<\/strong> \u662f\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u4e4b\u4e00\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u6765\u521b\u5efa\u5404\u79cd\u7c7b\u578b\u7684\u56fe\u5f62\uff0c\u5e76\u4e14\u53ef\u4ee5\u65b9\u4fbf\u5730\u5bfc\u51fa\u56fe\u5f62\u6570\u636e\u3002<strong>\u4f7f\u7528 Pandas \u5e93<\/strong> \u4e5f\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\uff0c\u5b83\u4e0d\u4ec5\u53ef\u4ee5\u5904\u7406\u6570\u636e\uff0c\u8fd8\u53ef\u4ee5\u65b9\u4fbf\u5730\u4e0e Matplotlib \u96c6\u6210\uff0c\u751f\u6210\u56fe\u5f62\u5e76\u5bfc\u51fa\u56fe\u5f62\u6570\u636e\u3002<strong>\u4f7f\u7528 Seaborn \u5e93<\/strong> \u4e5f\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u9009\u62e9\uff0c\u5b83\u63d0\u4f9b\u4e86\u66f4\u7b80\u6d01\u7684 API \u548c\u66f4\u7f8e\u89c2\u7684\u9ed8\u8ba4\u6837\u5f0f\u3002\u9664\u4e86\u8fd9\u4e9b\u5e93\u4e4b\u5916\uff0cPython \u8fd8\u6709\u8bb8\u591a\u5176\u4ed6\u7684\u7ed8\u56fe\u5e93\uff0c\u5982 Plotly\u3001Bokeh\u3001Altair \u7b49\uff0c\u8fd9\u4e9b\u5e93\u4e5f\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u6765\u521b\u5efa\u548c\u5bfc\u51fa\u56fe\u5f62\u6570\u636e\u3002\u65e0\u8bba\u60a8\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\uff0c\u90fd\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u5bfc\u51fa\u56fe\u5f62\u6570\u636e\uff0c\u5e76\u5c06\u5176\u4fdd\u5b58\u4e3a CSV\u3001Excel \u7b49\u683c\u5f0f\uff0c\u65b9\u4fbf\u540e\u7eed\u5206\u6790\u548c\u5904\u7406\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5bfc\u51fa\u7ed8\u56fe\u6570\u636e\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u5e93\u6765\u5bfc\u51fa\u7ed8\u56fe\u6570\u636e\u3002\u6700\u5e38\u7528\u7684\u5e93\u5305\u62ecMatplotlib\u548cPandas\u3002\u901a\u8fc7Matplotlib\u7ed8\u5236\u56fe\u5f62\u540e\uff0c\u53ef\u4ee5\u5229\u7528Pandas\u5c06\u6570\u636e\u4fdd\u5b58\u4e3aCSV\u6216Excel\u6587\u4ef6\u3002\u4f7f\u7528<code>DataFrame.to_csv()<\/code>\u6216<code>DataFrame.to_excel()<\/code>\u65b9\u6cd5\uff0c\u53ef\u4ee5\u8f7b\u677e\u5bfc\u51fa\u9700\u8981\u7684\u6570\u636e\u3002\u6b64\u5916\uff0c\u786e\u4fdd\u5728\u5bfc\u51fa\u4e4b\u524d\u6574\u7406\u597d\u6570\u636e\u683c\u5f0f\uff0c\u4ee5\u4fbf\u540e\u7eed\u5206\u6790\u548c\u4f7f\u7528\u3002<\/p>\n<p><strong>\u4f7f\u7528Matplotlib\u5bfc\u51fa\u56fe\u5f62\u6570\u636e\u65f6\uff0c\u6709\u54ea\u4e9b\u6700\u4f73\u5b9e\u8df5\uff1f<\/strong><br \/>\u5bfc\u51fa\u56fe\u5f62\u6570\u636e\u65f6\uff0c\u52a1\u5fc5\u786e\u4fdd\u6570\u636e\u7684\u51c6\u786e\u6027\u548c\u6e05\u6670\u5ea6\u3002\u5efa\u8bae\u5728\u5bfc\u51fa\u524d\u5bf9\u6570\u636e\u8fdb\u884c\u6e05\u6d17\uff0c\u5220\u9664\u7f3a\u5931\u503c\u6216\u5f02\u5e38\u503c\u3002\u540c\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u56fe\u8868\u4e2d\u7684\u6ce8\u91ca\u548c\u6807\u7b7e\u6765\u8bf4\u660e\u6570\u636e\u7684\u6765\u6e90\u548c\u610f\u4e49\uff0c\u4ee5\u4fbf\u540e\u7eed\u53c2\u8003\u3002\u4fdd\u5b58\u56fe\u5f62\u65f6\uff0c\u53ef\u4ee5\u9009\u62e9\u5e38\u89c1\u7684\u683c\u5f0f\uff0c\u5982PNG\u6216SVG\uff0c\u4ee5\u786e\u4fdd\u56fe\u5f62\u5728\u4e0d\u540c\u5e73\u53f0\u4e0a\u7684\u517c\u5bb9\u6027\u548c\u53ef\u8bfb\u6027\u3002<\/p>\n<p><strong>\u5982\u679c\u6211\u60f3\u5c06\u56fe\u5f62\u6570\u636e\u5bfc\u51fa\u4e3aExcel\u6587\u4ef6\uff0c\u6709\u54ea\u4e9b\u65b9\u6cd5\uff1f<\/strong><br \/>\u5c06\u56fe\u5f62\u6570\u636e\u5bfc\u51fa\u4e3aExcel\u6587\u4ef6\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528Pandas\u5e93\u3002\u9996\u5148\uff0c\u5c06\u7ed8\u56fe\u6570\u636e\u6574\u7406\u6210Pandas\u7684DataFrame\u683c\u5f0f\uff0c\u7136\u540e\u8c03\u7528<code>DataFrame.to_excel()<\/code>\u65b9\u6cd5\u8fdb\u884c\u5bfc\u51fa\u3002\u786e\u4fdd\u5b89\u88c5\u4e86<code>openpyxl<\/code>\u6216<code>xlsxwriter<\/code>\u5e93\uff0c\u4ee5\u652f\u6301Excel\u6587\u4ef6\u7684\u521b\u5efa\u3002\u5728\u5bfc\u51fa\u65f6\uff0c\u53ef\u4ee5\u81ea\u5b9a\u4e49\u6587\u4ef6\u540d\u548c\u5de5\u4f5c\u8868\u540d\u79f0\uff0c\u4ee5\u4fbf\u4e8e\u540e\u7eed\u7ba1\u7406\u548c\u5206\u6790\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u56fe\u5982\u4f55\u5bfc\u51fa\u753b\u56fe\u6570\u636e\uff1a \u4f7f\u7528 Matplotlib \u5e93\u3001\u4f7f\u7528 pandas \u5e93\u3001\u4f7f\u7528 seaborn [&hellip;]","protected":false},"author":3,"featured_media":1173474,"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\/1173467"}],"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=1173467"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1173467\/revisions"}],"predecessor-version":[{"id":1173478,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1173467\/revisions\/1173478"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1173474"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1173467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1173467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1173467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}