I use a for-loop to generate multiple images with fig.write_image in plotly. However, this gets very messy when there are many images. Is there a way to create a new folder and save these images in that folder when writing these images, so that all images will be stored in the same place rather than everywhere?
The code I used looks like below:
def draw(summary_df, data_df):
for i, row in summary_df.iterrows():
sub_df = data_df[(data_df.id== row.id) & (data_df.Timestamp >= row.start_time- datetime.timedelta(minutes=1)) & (data_df.Timestamp <= row.end_time +datetime.timedelta(minutes=1))]
fig = go.Figure()
fig.add_trace(go.Scatter(x=sub_df.Timestamp, y=sub_df.Data,
mode='lines+markers+text',
text = sub_df.Data,
textposition="top center",
textfont=dict(
family="arial",
size=10,
color="#6570f9") ))
fig.update_layout(
title=f'{i}. {row.id}, {row.Timestamp}',
xaxis_title="Timestamp",
yaxis_title="Measurement",
legend_title="Data",
font=dict(
size=11
)
)
fig.write_image(f"{row.id}-{row.Timestamp.strftime('%Y-%m-%d_%H_%M_%S')}.png")
fig.show()
os.makedirs(directory)to create new folders. Which is your criteria to create a new folder and save images there?