pdvega
pdvega copied to clipboard
Is there ax object with two y-scales (twinx)
My dataframe have two columns with different scale, I'd like twinx
function as Matplotlib
import numpy as np
import matplotlib.pyplot as plt
fig, ax1 = plt.subplots()
t = np.arange(0.01, 10.0, 0.01)
s1 = np.exp(t)
ax1.plot(t, s1, 'b-')
ax1.set_xlabel('time (s)')
# Make the y-axis label, ticks and tick labels match the line color.
ax1.set_ylabel('exp', color='b')
ax1.tick_params('y', colors='b')
ax2 = ax1.twinx()
s2 = np.sin(2 * np.pi * t)
ax2.plot(t, s2, 'r.')
ax2.set_ylabel('sin', color='r')
ax2.tick_params('y', colors='r')
fig.tight_layout()
plt.show()
Layered plots are available in master:
That said, I don't think twin axes in the way you're thinking about them (i.e. two different scales on one plot) will be supported, because it goes against viz best-practices and the people who created Vega-Lite have strong opinions on such things :smile:
@jakevdp We actually support it with resolve
. Check out https://github.com/vega/vega-lite/blob/master/examples/compiled/layer_bar_dual_axis.svg.
However, you're right that it is a bit controversial and you have to be very careful when using independent scales.
Thanks @domoritz – sorry to put words in your mouth :grin:
I'll think about how we might support this in pdvega while sticking to the pandas-like interface. I don't want to stray too far from that, as I think it would be more fruitful to focus on Altair for that kind of customization.
@jakevdp I completely agree. There are bigger fish to fry. Usually, a second chart/ a faceted chart is better than a dual axis chart with different scales.
@jakevdp @domoritz Yes, you're right