假设我有多个用于测试套件UPT_Synergy_graph22.csv
、UPT_C7000_graph22.csv
、SAT-Synergy-gen2_graph22.csv
的csv文件,像这样,我还有10个csv文件在所有文件build_id中都有相同的列,并通过百分比。我需要为所有这些文件绘制折线图。其中构建id是x轴,通过百分比是y轴。我需要得到每个csv文件的折线图(每个测试套件的平均值(。每个csv文件对应一个testsuite。
我只能得到一个csv文件的图形。我可以使用matplotlib获得图形,但我希望在网页/浏览器上获得图形,我知道我们可以使用Plotly模块/bookeh或任何能够在网络上获得相同图形结果的模块都会有所帮助。
请帮我解决这个问题。下面是我使用过的代码。帮助我使用Plotly模块转换代码,以获得上面提到的csv文件的折线图。
import pandas as pd
import matplotlib.pyplot as plt
from pathlib import Path
%matplotlib inline
# graphing parameters
plt.style.use('seaborn')
plt.rcParams['figure.figsize'] = (16.0, 10.0)
p = Path(r'c:UsersshivaradDocuments') # path to files
files = list(p.rglob('*graph22.csv')) # get files
# everything for here down, belongs in one Jupyter cell
plt.figure()
for f in files: # iterate through files
file_name = f.stem # get filename
df = pd.read_csv(f, dtype={'Pass Percentage': int, 'original_pass_percent': int}) # create
dataframe
print(df.head()) # this is here to verify df has data; it can be commented out or removed
plt.plot('build ID', 'Pass Percentage', data=df, label=file_name) # plot the data from each file
plt.legend(bbox_to_anchor=(1.04, 0.5), loc='center left')
plt.savefig('test.jpg') # verify there's plot in the file
plt.show() # outside the loop
我建议您之前连接或合并这些文件。由于您在files
变量中有文件列表,并且列都是相同的,可能是
dt = {'Pass Percentage': int, 'original_pass_percent': int}
df = pd.concat([pd.read_csv(f).assign(filename=f, dtype=dt) for f in files])
然后你可以使用绘图:
import plotly.express as px
px.line(df, x='build ID', y='Pass Percentage', color='filename')
假定"build ID"one_answers"Pass Percentage"是列名。