pdvega icon indicating copy to clipboard operation
pdvega copied to clipboard

How to add vertical and horizontal lines to figures?

Open BlackArbsCEO opened this issue 7 years ago • 6 comments

Please advise.

BlackArbsCEO avatar Feb 14 '18 00:02 BlackArbsCEO

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 avatar Feb 14 '18 03:02 jakevdp

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

BlackArbsCEO avatar Feb 14 '18 03:02 BlackArbsCEO

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

uribe-convers avatar Sep 11 '18 00:09 uribe-convers

Are you working in altair or in pdvega?

jakevdp avatar Sep 11 '18 01:09 jakevdp

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.

uribe-convers avatar Sep 11 '18 01:09 uribe-convers

Maybe you could comment on https://github.com/altair-viz/altair/issues/1124 with the problem you're having with the solution there.

jakevdp avatar Sep 11 '18 05:09 jakevdp