[英]Matplotlib is ignoring the given colourmap
這是我的情節:
這應該是表面圖。 如您所見,這有些失敗。 特別是它忽略了傳遞的顏色圖。
它被這樣稱呼:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
# Set global options
plt.rc('text', usetex=True)
plt.rc('font', family='sans-serif')
from scipy.interpolate import griddata
from matplotlib import cm
import numpy as np
class testPlot(object):
def __init__(self,trajDict):
# Concat dictionary into (n_i x D) for all i in speeds.
D = np.vstack(trajDict.values())
# Grid the data: [time,angle,velocity]
# time
self.X = D[:,0]
# angle
self.Y = D[:,1]
# velocity
self.Z = D[:,2]
# All vels
self.vels = [1.42,1.11,0.81,0.50]
def surfacePlot(self,intMethod,wire=False,surface=False):
zi = np.linspace(self.Z.min(),self.Z.max(),250)
xi = np.linspace(self.X.min(),self.X.max(),250)
yi = griddata((self.X, self.Z),
self.Y,
(xi[None,:], zi[:,None]),
method=intMethod)
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(111, projection='3d') #fig.gca(projection='3d')
zig, xig = np.meshgrid(xi, zi)
if surface:
surf = ax.plot_surface(zig, xig, yi,
cmap='Blues',
alpha=0.5)
ax.grid(False)
ax.set_ylabel('Velocity $[m/s]$')
ax.set_ylim([min(self.vels)-0.2, max(self.vels)+0.2])
ax.set_axis_off
ax.set_zlabel('Angle $[\circ]$')
ax.set_zlim([min(self.Y)-5,max(self.Y)+5])
ax.set_xlabel('Gait Cycle $[\%]$')
ax.set_xlim([self.X[0]-10,self.X[-1]])
plt.gca().invert_yaxis()
plt.show()
# Close existing windows
plt.close(fig)
傳遞此MWE數據進行測試:
OrderedDict([('a', array([[ 0. , 0. , 1.42],
[ 1. , 1. , 1.42],
[ 2. , 2. , 1.42],
[ 3. , 3. , 1.42],
[ 4. , 4. , 1.42]])),
('b', array([[ 0. , 1. , 1.11],
[ 1. , 2. , 1.11],
[ 2. , 3. , 1.11],
[ 3. , 4. , 1.11],
[ 4. , 5. , 1.11]])),
('c', array([[ 0. , 4. , 0.81],
[ 1. , 5. , 0.81],
[ 2. , 6. , 0.81],
[ 3. , 7. , 0.81],
[ 4. , 8. , 0.81]])),
('d', array([[ 0. , 9. , 0.5],
[ 1. , 10. , 0.5],
[ 2. , 11. , 0.5],
[ 3. , 12. , 0.5],
[ 4. , 13. , 0.5]]))])
至
myTest = testPlot(data)
myTest.surfacePlot('linear',surface=True)
應該給出一個有效的MWE(注意:它不會復制上面顯示的圖)。 請注意,數據需要采用上述格式才能工作。
您的代碼很好,顯示的圖是表面圖。 您可以知道,因為背景中的線條位於藍色區域的后面。 刪除Alpha設置,考慮使用其他cmap或為顏色欄指定自定義范圍以適合您的數據范圍。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.