Skip to content
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

smoother plotting code with seaborn #561

Open
sbenthall opened this issue Apr 14, 2022 · 0 comments
Open

smoother plotting code with seaborn #561

sbenthall opened this issue Apr 14, 2022 · 0 comments
Milestone

Comments

@sbenthall
Copy link
Collaborator

We have some archaic plotting code in the notebooks. Here's an example:

plt.figure(figsize=(12.5, 7.5))



for i, activity in enumerate(acts):

    colors = 'rgbkm'

    ta = activity.sum(1)
    rmta = ta.rolling(window).mean()
    rmtadna = rmta.dropna()
    
    rmtadna
    
    plt.plot_date(np.array(rmtadna.index),
                  np.array(rmtadna.values),
                  colors[i],
                  label=mls[i] + ' activity',
                  xdate=True)

    plt.legend()

This is a much more concise way to do it:

sum_acts = pd.DataFrame.from_records({mls[i] : a.sum(1) for i,a in enumerate(acts)})
sum_acts.index = sum_acts.index.map(date.fromordinal)
window = 100


sns.lineplot(data=sum_acts.rolling(window).mean().dropna(how='all'))

We can make the example code much cleaner and less cumbersome, expecially the earlier notebooks.

@sbenthall sbenthall added this to the 0.5 milestone Apr 14, 2022
@sbenthall sbenthall modified the milestones: 0.5, 0.6 May 16, 2023
@sbenthall sbenthall modified the milestones: 0.6, 0.7 Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant