在此输入图像描述 我这里有一个 3D 散点图,其中有一个平面穿过它。我用 Python 做了它。除了一件事之外,它是完美的。顶部附近有一个非常烦人的 1e7,我不想在那里。它旨在表示 z 轴和该侧数字的比例(例如,z 轴上的 2.5 实际上是 2.5*10^7,实际上是 25000000)。我不知道如何去掉 1e7,因为它使图表看起来不一样。我正在考虑要么让 z 轴只显示大比例数字 (25000000),要么保留较小比例数字,然后将 10^7 添加到带有“kg CO2”的标签上。有谁知道如何摆脱那个1e7?我将在下面提供我的代码。
import numpy as np
import matplotlib.pyplot as plt
def planeFit( x, y, z ):
z = 1035.09 * x + 428.68 * y - 216274.07
N = len(x)
xbar = sum(x) / N
ybar = sum(y) / N
zbar = sum(z) / N
Sxx = sum(x * x) / N - xbar * xbar
Syy = sum(y * y) / N - ybar * ybar
Sxy = sum(x * y) / N - xbar * ybar
Sxz = sum(x * z) / N - xbar * zbar
Syz = sum(y * z) / N - ybar * zbar
denominator = Sxx * Syy - Sxy ** 2
a = (Syy * Sxz - Sxy * Syz) / denominator
b = (Sxx * Syz - Sxy * Sxz) / denominator
c = zbar - a * xbar - b * ybar
return a, b, c
x = np.array( [ 940.5, 971.5, 1017, 1221.5, 1263, 1305, 1629, 1663, 1703, 4915, 4981, 5141, 6459, 6452, 6596, 8493, 8540, 8698, 9079, 9107.5, 9463.5, 11877.5, 11895.5, 6594.5, 15700, 15803.5, 15448.5, 14136.5, 14098.5, 14272.5, 18596.5, 18384.5, 18573, 24831.5, 24780, 24036, 20028, 19991, 19614.5, 25418.5, 25277.5, 19286.5, 25812.5, 25914.5, 25841, 405, 488.5, 601.5, 1881.5, 283, 2781, 3577.5, 4366, 5402.5, 5701.5, 7179, 8745.5, 8675.5, 12502.5, 10066 ] )
y = np.array( [ 500, 500, 500, 750, 750, 750, 1000, 1000, 1000, 2500, 2500, 2500, 3750, 3750, 3750, 5000, 5000, 5000, 4500, 4500, 4500, 6750, 6750, 6750, 9000, 9000, 9000, 7000, 7000, 7000, 10500, 10500, 10500, 14000, 14000, 14000, 9500, 9500, 9500, 14250, 14250, 14250, 19000, 19000, 19000, 500, 750, 1000, 2500, 3750, 5000, 4500, 6750, 9000, 7000, 10500, 14000, 9500, 14250, 19000 ] )
z = np.array( [ 1150000, 1200000, 1270000, 1590000, 1660000, 1740000, 2210000, 2290000, 2370000, 5890000, 5980000, 6170000, 8170000, 8190000, 8370000, 11200000, 11300000, 11500000, 10800000, 10900000, 11300000, 14900000, 15000000, 9330000, 20500000, 20700000, 20300000, 16900000, 16800000, 17100000, 23400000, 23200000, 23400000, 32300000, 32300000, 31500000, 23800000, 23800000, 23400000, 31900000, 31700000, 25300000, 35300000, 35500000, 35400000, 546000, 732000, 985000, 2670000, 3610000, 5120000, 4940000, 6440000, 8670000, 7580000, 10500000, 13900000, 11600000, 15400000, 21100000 ] )
a, b, c = planeFit( x, y, z )
fmt = "{:8.3f} "
print ( "Best fit a, b, c = ", (3 * fmt).format( a, b, c ) )
zfit = a * x + b * y + c
print( "Values x, y, z, zfit:" )
for i in range( len( x ) ):
print((4 * fmt).format(x[i], y[i], z[i], zfit[i]))
ax = plt.figure().add_subplot( projection='3d' )
ax.scatter( x, y, z, color='r' )
x1d = np.linspace( min( x ), max( x ), 5 )
y1d = np.linspace( min( y ), max( y ), 5 )
x2d, y2d = np.meshgrid( x1d, y1d )
zplane = a * x2d + b * y2d + c
ax.plot_surface( x2d, y2d, zplane, rstride=1, cstride=1, alpha=0.3 )
ax.set_xlabel('Frame weight (Tons)')
ax.set_ylabel('GFA/L (feet)')
ax.set_zlabel('GWP (kg CO2)')
plt.show()
如果您想将其添加到标签中,您只需将
z
数据除以 1e7
并将其添加到您的标签中即可。
# your code
z /= 1e7
# more code
ax.set_zlabel("GWP (kg CO2/1e7)")