【问题标题】:how to make scatter plot of two columns and divide x_axis in 3 column f1,f2,and f3如何制作两列的散点图并将 x_axis 划分为 3 列 f1、f2 和 f3
【发布时间】:2019-05-14 06:31:05
【问题描述】:

我有数据框,我想通过在区域 1 中仅绘制 f_x_f1 与 A_x_f1 的 2 个区域来绘制散点图,在区域 2 中绘制 f_x_f2 与 A_x_f2

如果有人可以为这个问题提供更好的解决方案

这是我的数据框的示例

df=pd.DataFrame({'f_x_f1':[0.3,0.28,0.34],'A_x_f1':[0.003,0.28,0.034],'f1':[0.4,0.4,0.4],'f_x_f2':[0.91,0.88,0.96],'A_x_f2':[0.003,0.28,0.034],'f2':[1.3,1.3,1.3]})

【问题讨论】:

  • 如果我们能看到您已经尝试过的内容会很有帮助:) 否则,您可以查看 matplotlib 文档 (matplotlib.org/api/_as_gen/matplotlib.pyplot.scatter.html) 以了解如何创建散点图
  • 我知道如何绘制简单的散点图 ax1 = ddd.plot(kind='scatter', x='freq_x_max_f1', y=['Amp_x_max_f1'], color='r') ,但我不知道如何根据列将绘图划分为 2 个区域

标签: python-3.x pandas matplotlib plotly


【解决方案1】:

这里,使用 matplotlib!

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt


### making some sample data
df = pd.DataFrame({"f_x_f1": np.random.randint(1,100,100) 
                    , "A_x_f1": np.random.randint(1,100,100)    
                    , "f_x_f2": np.random.randint(1,100,100) 
                    , "A_x_f2": np.random.randint(1,100,100) })

fig, ax = plt.subplots(nrows=1, ncols=2)
ax[0].scatter(df.f_x_f1,df.A_x_f1)
ax[0].set_title("f_x_f1 vs A_x_f1")

ax[1].scatter(df.f_x_f2,df.A_x_f2)
ax[1].set_title("f_x_f2 vs A_x_f2")

输出:

【讨论】:

  • @我想在同一轴上绘图,我上传了示例图片
猜你喜欢
  • 1970-01-01
  • 2013-10-28
  • 2017-01-07
  • 1970-01-01
  • 1970-01-01
  • 2021-02-15
  • 1970-01-01
  • 1970-01-01
  • 2019-12-21
相关资源
最近更新 更多