gpt4 book ai didi

python - Matplotlib 3D : Remove axis ticks & draw upper edge border?

转载 作者:太空宇宙 更新时间:2023-11-03 11:17:36 26 4
gpt4 key购买 nike

似乎某些适用于 matplotlib 2D 的方法可能不适用于 matplotlib 3D。我不确定。

我想删除所有轴上的刻度线,并将边缘颜色从底部和侧面延伸到顶部。我得到的最远的是能够将刻度线绘制为白色,这看起来很糟糕,因为它们呈现在边缘线的顶部。

下面是一大块独立的代码,结果如下图。非常感谢任何帮助!

import numpy as np
import matplotlib as mpl
from matplotlib import pyplot as plt
from matplotlib import animation
from mpl_toolkits.mplot3d import Axes3D

mpl.rcParams['ytick.color'] = 'white'
#mpl.rcParams['ytick.left'] = False

sample = np.random.random_integers(low=1,high=5, size=(10,3))

# Create a figure and a 3D Axes
fig = plt.figure(figsize=(5,5))

ax = Axes3D(fig)

#ax.w_xaxis.set_tick_params(color='white')

#ax.axes.tick_params
ax.axes.tick_params(bottom=False, color='blue')
##['size', 'width', 'color', 'tickdir', 'pad', 'labelsize',
##'labelcolor', 'zorder', 'gridOn', 'tick1On', 'tick2On',
##'label1On', 'label2On', 'length', 'direction', 'left', 'bottom',
##'right', 'top', 'labelleft', 'labelbottom',
##'labelright', 'labeltop', 'labelrotation']

colors = np.mean(sample[:, :], axis=1)

ax.scatter(sample[:,0], sample[:,1], sample[:,2],

marker='o', s=20, c=colors, alpha=1)

ax.tick_params(color='red')

frame1 = plt.gca()
frame1.axes.xaxis.set_ticklabels([])
frame1.axes.yaxis.set_ticklabels([])
frame1.axes.zaxis.set_ticklabels([])
#frame1.axes.yaxis.set_tick_params(color='white')

enter image description here

最佳答案

要回答问题的第一部分,关于剔除,禁用刻度线可能是最简单的:

for line in ax.xaxis.get_ticklines():
line.set_visible(False)
for line in ax.yaxis.get_ticklines():
line.set_visible(False)
for line in ax.zaxis.get_ticklines():
line.set_visible(False)

例如:

import numpy as np
import matplotlib as mpl
from matplotlib import pyplot as plt
from matplotlib import animation
from mpl_toolkits.mplot3d import Axes3D


sample = np.random.random_integers(low=1,high=5, size=(10,3))

# Create a figure and a 3D Axes
fig = plt.figure(figsize=(5,5))

ax = Axes3D(fig)

colors = np.mean(sample[:, :], axis=1)

ax.scatter(sample[:,0], sample[:,1], sample[:,2],

marker='o', s=20, c=colors, alpha=1)


ax = plt.gca()
ax.xaxis.set_ticklabels([])
ax.yaxis.set_ticklabels([])
ax.zaxis.set_ticklabels([])

for line in ax.xaxis.get_ticklines():
line.set_visible(False)
for line in ax.yaxis.get_ticklines():
line.set_visible(False)
for line in ax.zaxis.get_ticklines():
line.set_visible(False)

enter image description here

关于python - Matplotlib 3D : Remove axis ticks & draw upper edge border?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49027061/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com