2016-07-25 11 views
0

matplotlibで行列プロットを作成しようとしています。matplotlib subplotに特定の軸を追加するにはどうすればいいですか?

個々のプロットは、サブモジュールPolarAxesである特定のモジュールwindroseで作成されます。しかし、サブプロットkwargsと呼ばれるモジュールで定義された投影はないようです。サブクラスの引数の一部が欠落しているため、標準のpolar投影が機能しません。

私は成功しなかったいくつかのアプローチをテストしました(このポストを考慮した海軍地図でさえ:https://stackoverflow.com/a/25702476/3416205)。以下は私が試した最も近いものです。特定のWindroseAxesに関連する新しいmatplotlib投影法を適切に作成せずに、私が望むことをする方法はありますか?

import pandas as pd 
import matplotlib.pyplot as plt 
import matplotlib.gridspec as gridspec 
from 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) 

for (id_s, s) in enumerate(pd.unique(df.saison)): 
    for (id_jn, jn) in enumerate(pd.unique(df.jn)): 
     tmp = df.query('[email protected] & [email protected]') 
     _ = plt.subplot(gs[id_s, id_jn], polar=True) 
     wind_plot(tmp.wd, tmp.ws, title=s + ' - ' + jn, axes=_, fig=fig) 

plt.show() 

答えて

1

windroseモジュールからgithubのページは、実際にサブプロットの例を提供する:https://github.com/scls19fr/windrose/blob/master/samples/example_subplots.py

次のように動作します。

import pandas as pd 
import matplotlib.pyplot as plt 
import matplotlib.gridspec as gridspec 
from 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)) 

for (id_s, s) in enumerate(pd.unique(df.saison)): 
    for (id_jn, jn) in enumerate(pd.unique(df.jn)): 
     tmp = df.query('[email protected] & [email protected]') 
     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() 
関連する問題