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

How to plot contour lines on top of animation #114

Open
holivarez19 opened this issue Aug 31, 2022 · 4 comments
Open

How to plot contour lines on top of animation #114

holivarez19 opened this issue Aug 31, 2022 · 4 comments

Comments

@holivarez19
Copy link

Hello! I have successfully made animations (thank you!) but now am interested in making the animations look like the still figures I create. At the very least, how can I plot contour lines on top of the animations? See below for how I plot a still figure with contours for the top 300m of the ocean. Below the script is the resulting figure (top 300m and 300-6000m). Thank you!

fig,axs = plt.subplots(1,1,figsize=(15,2))

i = plt.pcolor(TLAT_A16, da.z_t, sDIC_NP_A16_plot.sel(time=slice(date1_1,date2_1)).mean('time'), cmap='plasma', vmin=1950, vmax=2450)

j = plt.contour(TLAT_A16, da.z_t, NP_pd_A16.sel(time=slice(date1_1,date2_1)).mean('time'), levels, colors='w', linewidth=2)
plt.clabel(j, fmt='%2.1f', colors='w', fontsize=28)

plt.title('')
plt.xlabel('')
plt.ylabel('')
plt.ylim(300,0) # reverse y-axis
plt.gca().invert_xaxis() # reverse x-axis for Atlantic
plt.tick_params(labelsize=15, length=15, direction='out', tick1On=True, labelbottom=True, labelleft=False)
plt.tick_params(axis='y', left=False)
cb = plt.colorbar()
cb.remove();

Picture1

@jbusecke
Copy link
Owner

jbusecke commented Sep 6, 2022

Hey @holivarez, sorry for the late reply. And thanks for using the package.

I think you are very close to what you want. Generally all you have to do is to wrap your plot into a function with the following signature:

func(ds, fig, tt, *args, **kwargs)

where ds is a dataset or dataarray, fig is a matplotlib.Figure, and tt is a logical timestep.

Similar to this example.

Let me know if this helps

@holivarez19
Copy link
Author

holivarez19 commented Sep 21, 2022 via email

@jbusecke
Copy link
Owner

If you have a fully reproducible example (e.g. a notebook with synthetic data that I can execute on my end), Id be happy to check it out and maybe have a quick zoom call if that helps.

@holivarez19
Copy link
Author

holivarez19 commented Sep 26, 2022 via email

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

2 participants