2013-07-29 27 views
8

我正在爲演示文稿準備,我有一些3D matplotlib數字的示例圖。然而,網格線太輕以至於看不到投影圖像。 example 3D image在3D Matplotlib圖上調整網格線圖

我嘗試使用網格的方法,對於2D人物的作品:

points = (5*np.random.randn(3, 50)+np.tile(np.arange(1,51), (3, 1))).transpose() 
fig = plt.figure(figsize = (10,10)) 
ax = fig.add_subplot(111, projection='3d') 
ax.scatter(points[:,0], points[:,1], points[:,2]) 
ax.view_init(elev=0., azim=0) 
ax.set_ylim([0, 60]) 
ax.set_zlim([0, 60]) 
ax.set_xlim([0, 60]) 
ax.set_zlabel('Cytokine') 
ax.set_ylabel('Parameter') 
ax.grid(linewidth=20) 

但是,這似乎並沒有對3D圖形工作。有什麼建議麼?

回答

3

不幸的是,這似乎並未公開。查看源代碼,關鍵的內部變量是調用_AXINFO,我們可以通過仔細的子類來覆蓋。

enter image description here

添加該代碼創建你的身材後,和風格也與字典custom_AXINFO

from mpl_toolkits.mplot3d import Axes3D 
import mpl_toolkits.mplot3d.axis3d as axis3d 

# New axis settings 
custom_AXINFO = { 
    'x': {'i': 0, 'tickdir': 1, 'juggled': (1, 0, 2), 
      'color': (0.00, 0.00, 0.25, .75)}, 
    'y': {'i': 1, 'tickdir': 0, 'juggled': (0, 1, 2), 
      'color': (0.20, 0.90, 0.90, 0.25)}, 
    'z': {'i': 2, 'tickdir': 0, 'juggled': (0, 2, 1), 
      'color': (0.925, 0.125, 0.90, 0.25)},} 

class custom_XAxis(axis3d.Axis): 
    _AXINFO = custom_AXINFO 

class custom_YAxis(axis3d.Axis): 
    _AXINFO = custom_AXINFO 

class custom_ZAxis(axis3d.Axis): 
    _AXINFO = custom_AXINFO 

class custom_Axes3D(Axes3D): 
    def _init_axis(self): 
     '''Init 3D axes; overrides creation of regular X/Y axes''' 
     self.w_xaxis = custom_XAxis('x', self.xy_viewLim.intervalx, 
            self.xy_dataLim.intervalx, self) 
     self.xaxis = self.w_xaxis 
     self.w_yaxis = custom_YAxis('y', self.xy_viewLim.intervaly, 
          self.xy_dataLim.intervaly, self) 
     self.yaxis = self.w_yaxis 
     self.w_zaxis = custom_ZAxis('z', self.zz_viewLim.intervalx, 
          self.zz_dataLim.intervalx, self) 
     self.zaxis = self.w_zaxis 

     for ax in self.xaxis, self.yaxis, self.zaxis: 
      ax.init3d() 

# The rest of your code below, note the call to our new custom_Axes3D 

points = (5*np.random.randn(3, 50)+np.tile(np.arange(1,51), (3, 1))).transpose() 
fig = plt.figure(figsize = (10,10)) 
ax = custom_Axes3D(fig) 

這是猴子修補它是最差的,並且不應被依賴爲更高版本工作。

固定面部顏色比網格線更容易,因爲這需要覆蓋一個__init__方法,儘管它可以用更多的工作完成。

將這件事暴露給最終用戶似乎並不困難,因此我可以想象這可能會在以後的版本中得到修復。

+0

它看起來像現在,你可以做ax.w_xaxis.plane.set_color((1,0,0)); ax.w_xaxis.plane.set_alpha(0.5)。它看起來像忽略了set_color中的alpha通道,但使用了set_alpha中的通道。 – Ben

16

如果您不介意讓所有的線條變粗,那麼您可以調整默認的rc設置。

給定圖,如:

enter image description here

我們可以添加:

import matplotlib as mpl 
mpl.rcParams['lines.linewidth'] = 2 

爲了提高全行的默認行寬,給人一種結果:

enter image description here

Altern atively,如果你覺得這個長相醜陋,你可以使用:

ax.w_xaxis.gridlines.set_lw(3.0) 
ax.w_yaxis.gridlines.set_lw(3.0) 
ax.w_zaxis.gridlines.set_lw(3.0) 

各軸的線寬度調整到3.0,產生:

enter image description here

爲了更新顏色,所以網格線真正流行,你可以添加:

ax.w_xaxis._axinfo.update({'grid' : {'color': (0, 0, 0, 1)}}) 
ax.w_yaxis._axinfo.update({'grid' : {'color': (0, 0, 0, 1)}}) 
ax.w_zaxis._axinfo.update({'grid' : {'color': (0, 0, 0, 1)}}) 

主要生產:

enter image description here

這些方法非常不方便,但據我所知,沒有簡單的方法來實現這些結果!希望這可以幫助;讓我知道如果你需要任何進一步的援助!

+0

@JudoWill - 如果它解決了你的問題,你應該接受這個答案! – Jamie