擅长:python、mysql、java
<p><code>Pandas</code>使用<code>matplotlib</code>作为基本绘图的库。在您的案例中,最简单的方法是使用以下内容:</p>
<pre><code>import pandas as pd
import numpy as np
#creating sample data
sample_data={'col_name_1':np.random.rand(20),
'col_name_2': np.random.rand(20)}
df= pd.DataFrame(sample_data)
df.plot(x='col_name_1', y='col_name_2', style='o')
</code></pre>
<p><a href="https://i.stack.imgur.com/Ajq4I.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ajq4I.png" alt="enter image description here"/></a></p>
<p>但是,如果您希望在不进入<code>matplotlib.</code>基本级别的情况下有更多自定义绘图,我建议使用<code>seaborn</code>作为替代解决方案。在这种情况下,您的解决方案如下:</p>
<pre><code>import pandas as pd
import seaborn as sns
import numpy as np
#creating sample data
sample_data={'col_name_1':np.random.rand(20),
'col_name_2': np.random.rand(20)}
df= pd.DataFrame(sample_data)
sns.scatterplot(x="col_name_1", y="col_name_2", data=df)
</code></pre>
<p><a href="https://i.stack.imgur.com/zyUVU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zyUVU.png" alt="enter image description here"/></a></p>