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

Positioning wind roses onto an existing x-y axis #188

Open
guidocioni opened this issue Sep 12, 2022 · 4 comments
Open

Positioning wind roses onto an existing x-y axis #188

guidocioni opened this issue Sep 12, 2022 · 4 comments

Comments

@guidocioni
Copy link

I have a meteogram with many variables and I would like to add a "strip" with wind roses like this

Screen Shot 2022-09-12 at 16 34 46

I'm using gridspec and already made space for an axis (ax_winds). Following the example on the documentation I'm trying to create an inset ax based on this axis and just tried to plot a single wind rose at a certain point in time.

gs = gridspec.GridSpec(nrows=4, ncols=1, height_ratios=[1, 1, 0.3, 1])
ax_winds = plt.subplot(gs[2])
wrax_cham = inset_axes(ax_winds,
         width=1,                             # size in inches
         height=1,                            # size in inches
         loc='center',                        # center bbox at given position
         bbox_to_anchor=(dset_city['valid_time'][5], 0.5), # position of the axe
         bbox_transform=ax_winds.transData,    # use data coordinate (not axe coordinate)
         axes_class=WindroseAxes,    # specify the class of the axe
)
wrax_cham.bar(wdir[:,5], wspd[:,5], opening=1, edgecolor='white')

But I'm getting some errors

ValueError: 'bboxes' cannot be empty

which are probably related to how I'm passing the parent axis to inset_axes.

Does anyone have an example of positioning multiple wind roses over a define time axis?

Full code is here if someone is interested https://github.com/guidocioni/icon_d2_eps/blob/master/plotting/plot_meteogram.py

@ocefpaf
Copy link
Collaborator

ocefpaf commented Sep 21, 2022

What happens if you pass the projection in your subplot?

plt.subplot(gs[2],  projection"="windrose")

@guidocioni
Copy link
Author

projection"="windrose"

Yep, that fixes the issue. However now I have two different wind roses appearing...

bfbde44d-5e30-4baa-9b76-5f3cde5b565c

Any idea what's going on? For now I'm just plotting a single time step

ax_winds = plt.subplot(gs[2], projection="windrose")
wspd = wind_speed(dset_city['u10'], dset_city['v10']).metpy.dequantify()
wdir = wind_direction(dset_city['u10'], dset_city['v10']).metpy.dequantify()
wrax_cham = inset_axes(ax_winds,
         width=0.8,                             # size in inches
         height=0.8,                            # size in inches
         loc='center',                        # center bbox at given position
         bbox_to_anchor=(dset_city['valid_time'][5], 0.3), # position of the axe
         bbox_transform=ax_winds.transData,    # use data coordinate (not axe coordinate)
         axes_class=WindroseAxes,    # specify the class of the axe
)
wrax_cham.contourf(wdir[:,30], wspd[:,30])
wrax_cham.tick_params(labelleft=False, labelbottom=False)
ax_winds.xaxis.set_major_locator(locator)
ax_winds.xaxis.set_major_formatter(formatter)
ax_winds.tick_params(axis='y', which='major', labelleft=False)
ax_winds.tick_params(axis='x', which='both', labelbottom=False)

@ocefpaf
Copy link
Collaborator

ocefpaf commented Sep 26, 2022

Not sure. If you can make a self-contained example that one can easily run without external data I can try to debug. My guess is that mpl is drawing the polar axis too and not only just the windrose.

@guidocioni
Copy link
Author

Not sure. If you can make a self-contained example that one can easily run without external data I can try to debug. My guess is that mpl is drawing the polar axis too and not only just the windrose.

I noticed that if I reduce the size of the axis then it seems to fill the background circle.
Anyhow, I took the time and packed a self-contained example with some test data (you need some data to plot...): it's really small, have a look.

https://drive.google.com/file/d/1SZo0rzTIO6nSDkHVywXg_NeZEX7ptg5L/view?usp=sharing
https://drive.google.com/file/d/14WfhMxCta5xHjkulaznmgxj6lUzt-Rcm/view?usp=sharing

I'm trying to reproduce something similar to this

Screen Shot 2022-09-26 at 17 27 14

of Course, it doesn't have to be exactly the same.

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