I would like to arrange several graphs in a row in plotly, but I can't move them because of an error.
The program summary reads all CSVs in the folder and divides each CSV into two.The fig.add_trace
appears twice in the for
statement because you want the split csv to be superimposed and displayed as a single graph.
Then, I want to create graphs for the number of csvs in the for
statement and arrange them vertically.
x_axis="G"
y_axis="D"
graphNumber = 11
file_names=glob.glob('*.csv')
def get_colorpalette(colorpalette, file_number):
palette=sns.color_palette(
colorpalette, file_number)
rgb = ['rgb({}, {}, {})'.format(*[x*256 for x in rgb])
for rgb in palette]
return rgb
colors=get_colorpalette('hls',graphNumber')
config=make_subplots(len(df_list_1), 1)
for i in range(len(df_list_1)):
for jin range (graphNumber):
print(i)
config.add_trace(
go.Scatter(
x=df_list_0[i][x_axis][parts_number*j:parts_number*(j+1)],
y=df_list_0[i][y_axis][parts_number*j:parts_number*(j+1)],
name = 'forward {:1f}'.format(j*0.1),
marker={'color':colors[j]}, mode='lines'
), i, 1
)
config.add_trace(
go.Scatter(
x=df_list_1[i][x_axis][parts_number*j:parts_number*(j+1)],
y=df_list_1[i][y_axis][parts_number*j:parts_number*(j+1)],
name = 'backward {:1f}'.format(j*0.1),
marker={'color':colors[j]}, mode='lines'
), i, 1
)
config.update_xaxes(matches='x')
config.show()
Error
------------------------------------------------------------------------------------------------
Exception Traceback (most recent call last)
<ipython-input-93-6f8e07a27f21>in<module>
5 for jin range (graphNumber):
6 print(i)
---->7fig.add_trace(
8 go.Scatter(
9 x = df_list_0[i][x_axis][ parts_number*j:parts_number*(j+1)],
c:\users\owner\appdata\local\programs\python\python38-32\lib\site-packages\plotly\basedatatypes.py in add_trace(self, trace, row, col, secondary_y)
1646 )
1647
->1648 return self.add_traces(
1649 data = [trace],
1650 rows = [row] if row is not None else,
c:\users\owner\appdata\local\programs\python\python38-32\lib\site-packages\plotly\basedatatypes.py in add_traces (self, data, rows, cols, secondary_ys)
1764 if rows is not None:
1765 for trace, row, col, secondary_y in zip (data, rows, cols, secondary_ys):
->1766self._set_trace_grid_position(trace, row, col, secondary_y)
1767
1768#Make deep copy of trace data (Optimize later if needed)
c:\users\owner\appdata\local\programs\python\python38-32\lib\site-packages\plotly\basedatatypes.py in_set_trace_grid_position(self, trace, row, col, secondary_y)
1846
1847grid_ref=self._validate_get_grid_ref()
->1848 return_set_trace_grid_reference(
1849 trace, self.layout, grid_ref, row, col, secondary_y
1850 )
c:\users\owner\appdata\local\programs\python\python38-32\lib\site-packages\plotly\subplots.py in_set_trace_grid_reference(trace, layout, grid_ref, row, col, secondary_y)
1309
1310 if row <=0:
->1311 raise Exception(
1312 "Row value is out of range." "Note: the starting cell is (1, 1)"
1313 )
Exception: Row value is out of range. Note: the starting cell is (1, 1)
The reason is that i
is i
in the fig.add_trace(...,i,1)
section as shown in the error message Note:the starting cell is (1,1)
.
Therefore, for i in range(len(df_list_1)):
must be for i in range(1,len(df_list_1)+1):
or fig.add_trace(...,i+1,1)
.
This post was posted as a community wiki based on @metropolis' comments.
610 GDB gets version error when attempting to debug with the Presense SDK (IDE)
911 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.