简体   繁体   English

如何删除 matplotlib 中 Axes3D 图表上的比例/轴?

[英]How to remove the scale/axes on a Axes3D Graph in matplotlib?

I'm plotting a 3D graph in jupyter notebook using python.我正在使用 python 在 jupyter 笔记本中绘制 3D 图。 Now I would like to remove this secondary scale in my plot, (not the x,y,z axes).现在我想在我的 plot 中删除这个二级刻度(不是 x、y、z 轴)。 I have tried using "axes.axis("off")", however, this only disables the normal x,y,z axes which I would like to keep.我曾尝试使用“axes.axis(“off”)”,但是,这只会禁用我想要保留的正常 x、y、z 轴。 I will attach my code and 2 images, one with the 3 axes + the scale I wish to delete, and the other with the axes I would like to keep disabled and the scale remaining.我将附上我的代码和 2 张图像,一张带有 3 个轴 + 我希望删除的比例,另一张带有我想禁用的轴和剩余的比例。 For clarity of the feature, I would like gone, any help would be appreciated.为了清晰起见,我想离开,任何帮助将不胜感激。

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()

Here is the image with the axes + the scale i want removed:这是带有轴+我要删除的比例的图像:

Here is the image with only the scale (the element i want to remove)这是只有比例的图像(我要删除的元素)

https://drive.google.com/file/d/1N5lTwj3s1tVgy_VuvHcSvf6p259wgDJJ/view?usp=sharing https://drive.google.com/file/d/1N5lTwj3s1tVgy_VuvHcSvf6p259wgDJJ/view?usp=sharing

To clarify, the intended result would have the second image only display the graph, and the first to only have the x,y,z axes.澄清一下,预期的结果将是第二张图像仅显示图形,而第一张图像仅具有 x、y、z 轴。

You can turn off your grid and rotate if you want.如果需要,您可以关闭grid并旋转。 You also have some imports that you're not using, I removed them just for now.你也有一些你没有使用的导入,我暂时删除了它们。

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()

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM