pdvega
pdvega copied to clipboard
How to add vertical and horizontal lines to figures?
Please advise.
In master, you can do this by layering, but that's not very convenient at the moment. It would be something like:
ax = data.vgplot(x='x', y='y')
# draw a line at y = 5
hline = pd.DataFrame({'x': data.x,
'y': 5 * np.ones_like(data.x)})
hline.vgplot(x='x', y='y', ax=ax)
(Note that this is not yet available in the version that's installable from pip.)
I've been thinking about this use case, and whether it would make sense to add ax.hlines([n1, n2]) and ax.vlines([n1, n2]) methods a la matplotlib for this use case.
@jakevdp thanks.
I think it would be helpful to add the hlines and vlines feature. My top use cases are to emphasize the zero line and to highlight important values when plotting distributions. I can also imagine wanting to shade a range between vlines, for example shading recessions when plotting economic time series.
@jakevdp I'm loving altair so far but I agree that adding hlines and vlines would make it even better! Hopefully something easy to use like ggplot's + geom_vline(xintercept=2).
I tried following the advice given on altair's issue #1124 but it didn't really work that well.
Keep up the good work and thank you for this awesome library.
Are you working in altair or in pdvega?
In Altair, just noticed that I posted on the pdvega repo, sorry about that. I was looking everywhere for ways to draw the vertical line and didn’t realize. I can post this to Altair if you prefer.
Maybe you could comment on https://github.com/altair-viz/altair/issues/1124 with the problem you're having with the solution there.