python - How to add specific axes to matplotlib subplot? -


i trying make matrix plot matplotlib.

the individual plots made specific module windrose subclasses polaraxes. there not seem projection defined in module called subplot kwargs. standard polar projection not work since of subclass arguments missing.

i have tested several approaches without success (even seaborn map considering post: https://stackoverflow.com/a/25702476/3416205). hereunder closest have tried. there way want without creating new matplotlib projection associated specific windroseaxes?

import pandas pd import matplotlib.pyplot plt import matplotlib.gridspec gridspec windrose import windroseaxes  df = pd.read_csv('https://raw.githubusercontent.com/antoinegautier/data/master/tmp.csv') fig = plt.figure() gs = gridspec.gridspec(4, 2)  def wind_plot(x, y, title=none, axes=none, fig=none):     ax = windroseaxes.from_ax()     ax.set_position(axes.get_position(fig))     ax.bar(x, y, normed=true, opening=0.8, edgecolor='white', bins=[0, 2.5, 5, 7.5, 10])     ax.set_title(title)  (id_s, s) in enumerate(pd.unique(df.saison)):     (id_jn, jn) in enumerate(pd.unique(df.jn)):         tmp = df.query('saison==@s & jn==@jn')         _ = plt.subplot(gs[id_s, id_jn], polar=true)         wind_plot(tmp.wd, tmp.ws, title=s + ' - ' + jn, axes=_, fig=fig)  plt.show() 

the github page windrose module provides example of subplots: https://github.com/scls19fr/windrose/blob/master/samples/example_subplots.py.

the following works.

import pandas pd import matplotlib.pyplot plt import matplotlib.gridspec gridspec windrose import windroseaxes  df = pd.read_csv('https://raw.githubusercontent.com/antoinegautier/data/master/tmp.csv')  fig = plt.figure(figsize=(20, 10)) gs = gridspec.gridspec(2, 4) gp = gs.get_grid_positions(fig)  # [bottom, top, left, right]  def wind_plot(x, y, title, fig, rect):     ax = windroseaxes(fig, rect)     fig.add_axes(ax)     ax.bar(x, y, normed=true, opening=0.8, edgecolor='white', bins=[0, 2.5, 5, 7.5, 10])     ax.set_title(title, position=(0.5, 1.1))  (id_s, s) in enumerate(pd.unique(df.saison)):     (id_jn, jn) in enumerate(pd.unique(df.jn)):         tmp = df.query('saison==@s & jn==@jn')         rect = [gp[2][id_s], gp[0][id_jn],                 gp[3][id_s]-gp[2][id_s],                 gp[1][id_jn]-gp[0][id_jn]]  # [left, bottom, width, height]         wind_plot(tmp.wd, tmp.ws, s + ' | ' + jn, fig, rect)  plt.show() 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -