Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Is there ax object with two y-scales (twinx) #19

Open
muxuezi opened this issue Feb 9, 2018 · 5 comments
Open

Is there ax object with two y-scales (twinx) #19

muxuezi opened this issue Feb 9, 2018 · 5 comments

Comments

@muxuezi
Copy link

muxuezi commented Feb 9, 2018

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()
@jakevdp
Copy link
Member

jakevdp commented Feb 9, 2018

Layered plots are available in master:
screen shot 2018-02-09 at 10 50 30 am

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 😄

@domoritz
Copy link
Contributor

domoritz commented Feb 9, 2018

@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.

@jakevdp
Copy link
Member

jakevdp commented Feb 9, 2018

Thanks @domoritz – sorry to put words in your mouth 😁

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.

@domoritz
Copy link
Contributor

domoritz commented Feb 9, 2018

@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.

@muxuezi
Copy link
Author

muxuezi commented Feb 11, 2018

@jakevdp @domoritz Yes, you're right

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants