I'm trying to plot one set of data with two different y-axes using Plotly. This seems like it should have an easy answer, but I've been unsuccessful so far...
I'm analyzing some Strava data and have a plot of average speed vs. distance. I want another y-axis on the right to show the equivalent pace (1/speed). I've read and googled but have only found examples of how to plot multiple series on multiple y-axes, not one series on two y-axes. I've found some clunky workarounds suggesting plotting two traces and manually setting yranges, etc. but this seems like something that should be easy to do.
For something concrete to work with, here's an example of the desired result using matplotlib. Note we only plot the data once, but use functions to set the ticks on the secondary y-axis. Does anything like this exist in plotly?
import matplotlib.pyplot as plt
xx = [1, 2, 3, 4]
y1 = [8, 7, 6, 5]
y2 = [60. / y for y in y1] # min/mile
fig, ax = plt.subplots()
ax.plot(xx, y1)
ax.set_ylabel('speed (miles/hr)')
ax.set_xlabel('distance (miles)')
def spd2pac(y):
return 60. / y
def pac2spd(y):
return 60. / y
secax = ax.secondary_yaxis('right', functions=(spd2pac, pac2spd))
secax.set_ylabel('pace (min/mile)')
plt.show()