python - 如何在 matplotlib 中删除 Axes3D 图形上的比例/轴?
问题描述
我正在使用 python 在 jupyter notebook 中绘制 3D 图。现在我想在我的图中删除这个二级比例(不是 x、y、z 轴)。我曾尝试使用“axes.axis(“off”)”,但是,这只会禁用我想要保留的正常 x、y、z 轴。我将附上我的代码和 2 张图像,一张带有 3 个轴 + 我希望删除的比例,另一张带有我想禁用的轴和剩余的比例。为了清晰起见,我想离开,任何帮助将不胜感激。
import warnings
warnings.simplefilter(action = 'ignore', category = FutureWarning)
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures
from sklearn.preprocessing import MinMaxScaler
from sklearn.metrics import r2_score
from scipy.stats import norm
from mpl_toolkits.mplot3d import Axes3D
import math
pd.options.mode.chained_assignment = None
data = pd.read_csv("./kc_house_data.csv")
size = data['sqft_living'].values.reshape(-1, 1)
price = data['price'].values.reshape(-1, 1)
bedrooms = data['bedrooms'].values.reshape(-1, 1)
size_scaler = MinMaxScaler()
price_scaler = MinMaxScaler()
bedroom_scaler = MinMaxScaler()
norm_size = size_scaler.fit_transform(size).reshape(-1)
norm_price = price_scaler.fit_transform(price).reshape(-1)
norm_bedrooms = bedroom_scaler.fit_transform(bedrooms).reshape(-1)
graphWidth = 400
graphHeight = 300
f = plt.figure(figsize = (graphWidth / 100.0, graphHeight / 100.0), dpi = 100)
matplotlib.pyplot.grid(True)
axes = Axes3D(f)
axes.scatter(norm_size, norm_bedrooms, norm_price)
plt.show()
https://drive.google.com/file/d/1N5lTwj3s1tVgy_VuvHcSvf6p259wgDJJ/view?usp=sharing
澄清一下,预期的结果将是第二张图像仅显示图形,而第一张图像仅具有 x、y、z 轴。
解决方案
如果需要,您可以关闭grid
并旋转。你也有一些你没有使用的导入,我暂时删除了它们。
import warnings
warnings.simplefilter(action = 'ignore', category = FutureWarning)
import pandas as pd
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures
from sklearn.preprocessing import MinMaxScaler
from sklearn.metrics import r2_score
from scipy.stats import norm
from mpl_toolkits.mplot3d import Axes3D
import math
pd.options.mode.chained_assignment = None
data = pd.read_csv("kc_house_data.csv")
size = data['sqft_living'].values.reshape(-1, 1)
price = data['price'].values.reshape(-1, 1)
bedrooms = data['bedrooms'].values.reshape(-1, 1)
size_scaler = MinMaxScaler()
price_scaler = MinMaxScaler()
bedroom_scaler = MinMaxScaler()
norm_size = size_scaler.fit_transform(size).reshape(-1)
norm_price = price_scaler.fit_transform(price).reshape(-1)
norm_bedrooms = bedroom_scaler.fit_transform(bedrooms).reshape(-1)
graphWidth = 400
graphHeight = 300
f = plt.figure(figsize = (graphWidth / 100.0, graphHeight / 100.0), dpi = 100)
axes = Axes3D(f)
axes.scatter(norm_size, norm_bedrooms, norm_price, cmap="RdYlGn", edgecolors="black")
plt.show()
推荐阅读
- c# - 照片矩阵
- xamarin - Xamarin.Forms UWP - 将 WebView.Source 设置为 HtmlWebViewSource 两次处理脚本
- liquibase - Liquibase 上下文中的括号和逗号
- php - 如何在一个项目中添加数组项目?
- spring - OneToMany 不返回从其他实体保存的值
- javascript - Google Maps API 和 Angular 1 中的变量范围
- python - Python从查询创建嵌套的html表
- javascript - admin.auth().currentUser; 在云函数中返回未定义
- css - CSS 通过“react-scripts build”命令破坏部署
- javascript - 在包含复杂嵌套数组的 javascript 对象中查找项目