Plotly使用问题
折线图Y轴自适应问题
这里使用了列表和pd的DataFrame作为数据源
data_6040 = []
data_6041 = []
strace_path = r'C:\Users\QYJ\Desktop\RunTimeOld\xj.csv'
with open (strace_path, 'r') as fp:
for i in csv.DictReader(fp):
data_6040.append(i['6040'])
data_6041.append(i['6041'])
df = pd.read_csv(strace_path)
当我们用plotly画图时, 数据源选择list的时候
fig = go.Figure()
scatter_6040 = go.Scatter(y=data_6040)
scatter_6041 = go.Scatter(y=data_6041)
# scatter_6040 = go.Scatter(y=df['6040'])
# scatter_6041 = go.Scatter(y=df['6041'])
fig.add_trace(
scatter_6040
)
fig.add_trace(
scatter_6041
)
fig.update_yaxes(
automargin=False,
)
fig.update_layout (
template='plotly' # gridon is set as normal
)
fig.show()
图象如下
可以看出这里的Y轴数据做过了优化, 将两个折线图的数据分开来显示, 并且蓝色折线图的128数据放在了中间显示以达到有限的空间将整个信息都显示出来
将数据源换成pandas以后
fig = go.Figure()
# scatter_6040 = go.Scatter(y=data_6040)
# scatter_6041 = go.Scatter(y=data_6041)
scatter_6040 = go.Scatter(y=df['6040'])
scatter_6041 = go.Scatter(y=df['6041'])
fig.add_trace(
scatter_6040
)
fig.add_trace(
scatter_6041
)
fig.update_yaxes(
automargin=False,
)
fig.update_layout (
template='plotly' # gridon is set as normal
)
fig.show()
图象如下
这里的数据就没有做过优化, Y轴数据按照顺序给出
想知道给plotly配置什么参数能达到优化Y轴显示的功能