issue_comments: 1008210008
This data as json
html_url | issue_url | id | node_id | user | created_at | updated_at | author_association | body | reactions | performed_via_github_app | issue |
---|---|---|---|---|---|---|---|---|---|---|---|
https://github.com/pydata/xarray/pull/5622#issuecomment-1008210008 | https://api.github.com/repos/pydata/xarray/issues/5622 | 1008210008 | IC_kwDOAMm_X848GBBY | 14371165 | 2022-01-09T01:47:20Z | 2022-01-09T01:47:20Z | MEMBER | Gotten a little sidetracked with line plots for a while now. I'm annoyed that all the primitives are different for each plotting type, e.g Collections, Line2D, list of Line2D, etc. It makes it hard to use similar code paths.
So I've been trying out LineCollection a little which behaves very similarly to In the example below you can clearly see that we have two curves where the hue changes somehow over time. But I'm having trouble understanding how to determine what's supposed to be a line. For example if x and y were 4d arrays how should it be split? scatter uses ravel to get around these hard questions. Maybe you can ravel just certain dimensions? Like if Not sure how to do that in xarray though. Thoughts, ideas or other examples are appreciated.
```python
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import numpy as np
from matplotlib.collections import LineCollection
import numpy as np
np.random.seed(42)
dates = np.arange("2017-01-01", "2017-06-20", dtype="datetime64[D]" )
y = np.cumsum(np.random.normal(size=len(dates)))
y2 = np.cumsum(np.random.normal(size=len(dates)))
c = np.cumsum(np.random.normal(size=len(dates)))
c2 = np.cumsum(np.random.normal(size=len(dates)))
s = 1 + np.minimum(np.cumsum(np.random.normal(size=len(dates))), 0)
s2 = 1 + np.minimum(np.cumsum(np.random.normal(size=len(dates))), 0)
fig, ax = plt.subplots()
#convert dates to numbers first
inxval = mdates.date2num(dates)
points = np.array([inxval, y]).T.reshape(-1,1,2)
segments = np.concatenate([points[:-1],points[1:]], axis=1)
lc = LineCollection(segments, cmap="plasma", linewidth=s)
lc.set_array(c)
p = ax.add_collection(lc)
points2 = np.array([inxval, y2]).T.reshape(-1,1,2)
segments2 = np.concatenate([points2[:-1],points2[1:]], axis=1)
lc2 = LineCollection(segments2, cmap="plasma", linewidth=s2)
lc2.set_array(c2)
p = ax.add_collection(lc2)
fig.colorbar(p, ax=ax)
ax.xaxis_date()
ax.autoscale_view()
plt.show()
```
|
{ "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
948049609 |