【发布时间】:2017-05-03 12:01:08
【问题描述】:
我是编程新手,我花了很多时间寻找解决方案,但我似乎无法正确解决。 我有一些存储在字典中的测量数据集。我想创建一个图表,其中显示了来自测量数据的所有曲线。我正在尝试创建一个空图,然后遍历字典并将两个存储的 dataFrame 的两列添加为每个键的图的跟踪。
我做错了什么或者我该怎么做?
import plotly as py
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import plotly.graph_objs as go
figure1 = go.Figure()
for key in dictofdf:
trace1 = go.Scatter(
y=df_1['force'],
x=df_1['displacement'],
mode='line',
marker=go.Marker(color='rgb(255, 127, 14)'),
name='load'
)
trace2 = go.Scatter(
y=df_2['force'],
x=df_2['displacement'],
mode='line',
marker=go.Marker(color='rgb(55, 137, 3)'),
name='unload'
)
figure1.append_trace(trace1,1,1)
figure1.append_trace(trace2,1,1)
py.offline.iplot(figure1, filename='force-displacement-data', image='jpeg')
使用我目前的代码,我得到了错误
--------------------------------------------------------------------------- TypeError Traceback (most recent call
last) <ipython-input-42-4ea5d9b8a638> in <module>()
50 )
51
---> 52 figure1.append_trace(trace1,1,1)
53 figure1.append_trace(trace2,1,1)
54
C:\Users\xxxxx\Anaconda3\lib\site-packages\plotly\graph_objs\graph_objs.py
in append_trace(self, trace, row, col)
914 "Note: the starting cell is (1, 1)")
915 try:
--> 916 ref = grid_ref[row-1][col-1]
917 except IndexError:
918 raise Exception("The (row, col) pair sent is out of range. "
TypeError: 'NoneType' object is not subscriptable
【问题讨论】: