Skip to content

1D line plot with data on the x axis #575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rabernat opened this issue Sep 15, 2015 · 13 comments · Fixed by #1926
Closed

1D line plot with data on the x axis #575

rabernat opened this issue Sep 15, 2015 · 13 comments · Fixed by #1926

Comments

@rabernat
Copy link
Contributor

Consider the following Dataset, representing a function f = cos(z)

z = np.arange(10)
ds = xray.Dataset( {'f': ('z', np.cos(z))}, coords={'z': z})

If I call

ds.f.plot()

xray naturally puts "z" on the x-axis.

However, since z represents the vertical dimension, it would be more natural do put it on the y-axis, i.e.

plt.plot(ds.f, ds.z)

This is conventional in atmospheric science and oceanography for buoy data or balloon data.

Is there an easy way to do this with xray's plotting functions? I scanned the code and didn't see an obvious solution, but maybe I missed it.

@shoyer
Copy link
Member

shoyer commented Sep 15, 2015

I don't think we have an easy way to do this now.

Seaborn uses the keyword argument orient='h' or orient='v' to control orientation for categorical plots like violinplot. That might be a reasonable API to emulate here.

@clarkfitzg
Copy link
Member

Not possible now. Wouldn't be much trouble to add it though. @drewokane has been working on generalizing the 1d plotting in #566. This might be a nice thing to include.

@drewokane
Copy link

I agree orient would be a natural keyword to use for this situation.

@rabernat
Copy link
Contributor Author

Yes, 👍 orient.

@jhamman
Copy link
Member

jhamman commented Sep 16, 2015

I'm fine with orient={h, v} but I will offer a few other alternatives.

  • Explicit is better than implicit. I know what h and v mean but it is more explicit to say horizontal or vertical. These keywords also require less in terms of documentation.
  • Can we only imagine two options for the orientation? If so, maybe a True/False keyword is a better way to go (orient_horizontal=True)? Maybe not?

I'm not married to either of the opinions I just mentioned, just a few thoughts.

@kuchaale
Copy link

kuchaale commented Nov 1, 2017

Would it make sense to have such minimalistic line function?

@shoyer
Copy link
Member

shoyer commented Nov 1, 2017

I wonder if it makes more sense to make .plot() a Dataset method as well, so we could write things like ds.plot.line(x='f', y='z') and ds.plot.scatter(x='f', y='z'). Writing ds.f.plot(orient='h') is much less self-explanatory.

@fmaussion
Copy link
Member

In a first step at least, we could add the x and y arguments to the line plot method to make the API consistent with the 2d plot methods (http://xarray.pydata.org/en/latest/api.html#plotting). But now that I think of it, they should be kwargs, not args

I wonder if it makes more sense to make .plot() a Dataset method as well

Yes. This might be a bit of an undertaking as there will be several possible cases to handle but this is a good idea!

@shoyer
Copy link
Member

shoyer commented Nov 2, 2017

In a first step at least, we could add the x and y arguments to the line plot method to make the API consistent with the 2d plot methods

If an argument is a 1D DataArray, how do we indicate this array's data? The best I can think of is to use some sort of sentinel value, maybe None: df.f.plot(x=None, y='z')

@kuchaale
Copy link

I think plotting two 1D variables from one Dataset against each other may be useful. However, I was not able to figure out yet how to proceed with it (see my amateur PR).

@dcherian
Copy link
Contributor

@kuchaale I see you have an open PR. Are you planning to revisit this soon? If not, I'd like to build off what you started and tackle this bit (not the Dataset method)

In a first step at least, we could add the x and y arguments to the line plot method to make the API consistent with the 2d plot methods (http://xarray.pydata.org/en/latest/api.html#plotting).

@kuchaale
Copy link

@dcherian go ahead. I planned to revisit it, but it would not be definitely soon.

@dcherian
Copy link
Contributor

@kuchaale Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants