2017-05-26 2 views
1

私は、個々のモデルのグリッドボックスで円グラフを使用して世界の地図を作成しています。私は地図と海岸線をカートリッジで作成します。 inset_axesを使用して作成した円グラフ。残念ながら、円グラフは海岸線を隠しており、私はそれらをはっきりと見たいと思います。Cartesの海岸線がinset_axesによって隠されているAxes.pieの使用

最小作業例は:

import cartopy.crs as ccrs 
import numpy as np 
import cartopy.feature as feature 
import matplotlib.pyplot as plt 

def plot_pie_inset(dataframe_pie,ilat_pie,ilon_pie,axis_main,width_local,alpha_local): 
    ax_sub= inset_axes(axis_main, width=width_local, height=width_local, loc=3, bbox_to_anchor=(ilat_pie, ilon_pie),bbox_transform=axis_main.figure.transFigure, borderpad=0.0) 
    wedges,texts= ax_sub.pie(dataframe_pie,colors=colors_dual) 
    for w in wedges: 
     w.set_linewidth(0.02) 
     w.set_alpha(alpha_local) 
     w.set_zorder(1) 
    plt.axis('equal') 

colors_dual=['RosyBrown','LightBlue'] 
lat_list= np.arange(0.2,0.7,0.05) 

fig= plt.figure() 
ax_main= plt.subplot(1,1,1,projection=ccrs.PlateCarree()) 
ax_main.coastlines(zorder=3) 
for ilat in np.arange(len(lat_list)): 
    plot_pie_inset([75,25],lat_list[ilat],0.72,ax_main,0.2,0.9) 

plt.show() 

私は、アルファ値を下げることにより、部分的に透明な円グラフを作ることによって海岸線を見ることができます。しかし、これにより色がやや消えてしまいます。私の目的は海岸線を一番上の層にすることです。

私は 'zorder'を使用して海岸線を最上位層に強制しようとしました。しかし、 'zorder'はinset_axesやax.pieに渡すことはできませんので、色のパッチを円グラフで半透明にしました。これは、ax_main.coastlinesに独自の 'zorder'がないために失敗します。海岸線のzorderはax_mainのそれと結びついているようです。 ax_mainのzorderを増やすことには利点はありません。

大変歓迎された提案です。

答えて

2

問題は、各軸が別の軸の上または下にあることです。したがって、軸の中のアーティストのzorderを変更することは、ここでは役に立ちません。原理的には、インセット軸を主軸の後ろに置いて、軸自体のzorderを設定することができます。

ax_sub.set_zorder(axis_main.get_zorder()-1) 

CartopyのGeoAxesは独自のバックグラウンドパッチを使用します。これはその後、目に見えないように設定する必要があります。

ax_main.background_patch.set_visible(False) 

コンプリート例:

import cartopy.crs as ccrs 
import numpy as np 
import matplotlib.pyplot as plt 
from mpl_toolkits.axes_grid1.inset_locator import inset_axes 

def plot_pie_inset(dataframe_pie,ilat_pie,ilon_pie,axis_main,width_local,alpha_local): 
    ax_sub= inset_axes(axis_main, width=width_local, height=width_local, loc=3, 
         bbox_to_anchor=(ilat_pie, ilon_pie), 
         bbox_transform=axis_main.transAxes, 
         borderpad=0.0) 
    wedges,texts= ax_sub.pie(dataframe_pie,colors=colors_dual) 
    for w in wedges: 
     w.set_linewidth(0.02) 
     w.set_alpha(alpha_local) 
     w.set_zorder(1) 
    plt.axis('equal') 
    # Put insets behind main axes 
    ax_sub.set_zorder(axis_main.get_zorder()-1) 

colors_dual=['RosyBrown','LightBlue'] 
lat_list= np.arange(0.2,0.7,0.05) 

fig= plt.figure() 
ax_main= plt.subplot(1,1,1,projection=ccrs.PlateCarree()) 
ax_main.coastlines() 

# set background patch invisible, such that axes becomes transparent 
# since the GeoAxes from cartopy uses a different patch as background 
# the following does not work 
# ax_main.patch.set_visible(False) 
# so we need to set the GeoAxes' background_patch invisible 
ax_main.background_patch.set_visible(False) 

for ilat in np.arange(len(lat_list)): 
    plot_pie_inset([75,25],lat_list[ilat],0.72,ax_main,0.2,0.9) 

plt.show() 

enter image description here

+0

すばやく便利な返信をありがとうございました。 – LeightonRegayre

+0

バックグラウンドパッチを不可視に設定することで、海岸線を見えるようにする方法がわかりません。 GeoAxesのバックグラウンドと海岸線、またはバックグラウンドの両方でset_visible(False)が使用されていますか? 私は、目に見える部分と部分的に透明な部分には微妙な違いがあると思います。つまり、目に見えないことは海岸線の線が見えることを意味します。あれは正しいですか? もう一度おねがいします! – LeightonRegayre

+1

背景は軸のすべての背後にある白い矩形です(したがって海岸線の背後にもあります)。インセットを主軸の後ろに置くと、この白い四角形がインセットの前にあり、それらを隠します。しかし、背景を見えなくする(すなわち、白い四角形を消去する)ことで、主軸の背後にあるすべてのものが見えるようになります。 – ImportanceOfBeingErnest

1

代替ソリューションはinset_axesを使用することを怠ったが、同様の結果を達成同僚によって示唆しています。主な違いは、この解の座標系は図座標ではなく元の緯度/経度座標であることです。

def plot_pie_direct(dataframe_pie,ilat_pie,ilon_pie,axis_main,width_local,alpha_local): 
    wedges,texts= ax_main.pie(dataframe_pie,colors=colors_aer_atm,radius=width_local) 
    for w in wedges: 
     w.set_linewidth(0.02) ## Reduce linewidth to near-zero 
     w.set_center((ilat_pie,ilon_pie)) 
     w.set_zorder(0) 

fig= plt.figure() 
ax_main= plt.axes(projection=ccrs.PlateCarree()) 
ax_main.coastlines(zorder=3) 
ax_main.set_global() 
lim_x= ax_main.get_xlim() 
lim_y= ax_main.get_ylim() 
for ilat in np.arange(len(lat_list_trim)): 
    plot_pie_direct(frac_aer_atm_reshape_trim[:,ilat,ilon],x_val_pies[ilon],y_val_pies[ilat],ax_main,lat_list_diff_trim,0.9) 

ax_main.coastlines(zorder=3) 
ax_main.set_xlim(lim_x) 
ax_main.set_ylim(lim_y) 
plt.show() 
関連する問題