Skip to content

Commit 9a2767b

Browse files
committed
add append_trace method to Figure
1 parent 0437513 commit 9a2767b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

plotly/graph_objs/graph_objs.py

+31
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,37 @@ def print_grid(self):
929929
print(grid_str)
930930
Figure.print_grid = print_grid
931931

932+
def append_trace(self, trace, row, col):
933+
try:
934+
grid_ref = self['_grid_ref']
935+
except KeyError:
936+
raise Exception("In order to use Figure.append_trace, "
937+
"you must first use tools.make_subplots "
938+
"to create a subplot grid.")
939+
try:
940+
ref = grid_ref[row-1][col-1]
941+
except IndexError:
942+
raise Exception("The (row, col) pair sent is out of range. "
943+
"Use Figure.print_grid to view the subplot grid. ")
944+
if 'scene' in ref[0]:
945+
trace['scene'] = ref[0]
946+
if ref[0] not in self['layout']:
947+
raise Exception("Something went wrong. "
948+
"The scene object for ({r},{c}) subplot cell "
949+
"got deleted.".format(r=row, c=col))
950+
else:
951+
xaxis_key = "xaxis{ref}".format(ref=ref[0][1:])
952+
yaxis_key = "yaxis{ref}".format(ref=ref[1][1:])
953+
if (xaxis_key not in self['layout']
954+
or yaxis_key not in self['layout']):
955+
raise Exception("Something went wrong. "
956+
"An axis object for ({r},{c}) subplot cell "
957+
"got deleted.".format(r=row, c=col))
958+
trace['xaxis'] = ref[0]
959+
trace['yaxis'] = ref[1]
960+
self['data'] += [trace]
961+
Figure.append_trace = append_trace
962+
932963
return Figure
933964

934965
Figure = get_patched_figure_class(Figure)

0 commit comments

Comments
 (0)