【发布时间】:2020-07-24 06:14:59
【问题描述】:
我正在学习 Python(即将出现基本问题),并且我有很多数据来自一些分析,它们是如下所示的 CSV 文件:
我正在尝试重新创建下面的图(目前我在 Excel 中做这样的事情,随着数据量和可视化的复杂性,我想让事情变得更有效率。
我尝试使用 For 循环的概念为该列中的每个不同的“SectionName”绘制一条线,但显然遗漏了一些东西。
#read CSV
df=pd.read_csv('/Users/F/Documents/Data/LinesLoopTest.csv')
#Make Variables from dataframe columns
Value = df['Value']
Position = df['Xposition']
Section = df['SectionName']
#Setup Figure
fig = plt.figure(figsize=(6,3))
ax1 = fig.add_subplot(1,1,1)
ax1.set_title('Sections')
ax1.set_xlabel("XPosition")
ax1.set_ylabel("Value")
#plot lines by SectionName
for name in ['A', 'B', 'C']:
plt.plot(Position, Value)
plt.show()
我意识到这是一个简单的问题,到目前为止我还没有找到一个解释,我可以真正理解这个过程,以至于我可以重新创建它然后在它的基础上进行构建。
【问题讨论】:
-
请不要发布代码、数据或 Tracebacks 的图像。将其复制并粘贴为文本,然后将其格式化为代码(选择它并输入
ctrl-k)...Discourage screenshots of code and/or errors
标签: python for-loop matplotlib plot