I have to plot lines on multiple y-axes. In plotly, however, the axis generation within go.Layout is quite verbose like in this example from the plotly documentation: https://plot.ly/python/multiple-axes/
layout = go.Layout(
title='multiple y-axes example',
width=800,
xaxis=dict(
domain=[0.3, 0.7]
),
yaxis=dict(
title='yaxis title',
titlefont=dict(
color='#1f77b4'
),
tickfont=dict(
color='#1f77b4'
)
## repeat for every new y-axis.
In matplotlib i like to save code by generating all the different axes and handling the plotting in loops like so:
import matplotlib.pyplot as plt
import numpy as np
# generate dummy data
data = []
for i in range(5):
arr = np.random.random(10) * i
data.append(arr)
colors = ['black', 'red', 'blue', 'green', 'purple']
labels = ['label1', 'label2', 'label3', 'label4', 'label5']
# define other paramters (e.g. linestyle etc.) in lists
fig, ax_orig = plt.subplots(figsize=(10, 5))
for i, (arr, color, label) in enumerate(zip(data, colors, labels)):
if i == 0:
ax = ax_orig
else:
ax = ax_orig.twinx()
ax.spines['right'].set_position(('outward', 50 * (i - 1)))
ax.plot(arr, color=color, marker='o')
ax.set_ylabel(label, color=color)
ax.tick_params(axis='y', colors=color)
fig.tight_layout()
plt.show()

Due to the dict-syntax used in object generation I seem to be unable to make something like that work in plotly. I have tried generating the axes-dicts by loops in advance and passing those to go.Layout but with no success.
If anybody could point out an elegant way to reduce redundancy it will be greatly appreciated.
All the best and thanks in advance.
