我试图使用"情节"功能,但它根本不适用于我的情况."ggplot"工作在2D的情况下,但是在添加一个轴时会出错.如何解决这个问题?
ggplot(data,aes(x=D1,y=D2,z=D3,color=Sample))+geom_point()
Run Code Online (Sandbox Code Playgroud)
如何添加一个轴并获得3D图?谢谢.
我在Python中有三个列表xs,ys,zs的数据点,我正在尝试matplotlib使用该scatter3d方法创建一个3d图.
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
plt.xlim(290)
plt.ylim(301)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.scatter(xs, ys, zs)
plt.savefig('dateiname.png')
plt.close()
Run Code Online (Sandbox Code Playgroud)
在plt.xlim()和plt.ylim()做工精细,但我没有找到一个函数来设置的边框z方向.我怎么能这样做?
我希望利用Plotly中的强大功能,但我很难弄清楚如何将回归平面添加到三维散点图中.以下是如何开始使用3d绘图的示例,是否有人知道如何在下一步中添加并添加平面?
library(plotly)
data(iris)
iris_plot <- plot_ly(my_df,
x = Sepal.Length,
y = Sepal.Width,
z = Petal.Length,
type = "scatter3d",
mode = "markers")
petal_lm <- lm(Petal.Length ~ 0 + Sepal.Length + Sepal.Width,
data = iris)
Run Code Online (Sandbox Code Playgroud) 我可以设置参数来plotly.graph_objs.go.Scatter3d使图形全屏显示或设置更高的保存分辨率吗?使用内置保存绘图功能时保存的当前分辨率为983x525。我希望至少能达到 1080p。
trans = .6
trace1 = go.Scatter3d(
x = cluster0["PC1_3d"],
y = cluster0["PC2_3d"],
z = cluster0["PC3_3d"],
mode = "markers",
name = "Cluster 0",
marker = dict(color = f'rgba(255, 0, 0, {trans})'),
text = None)
trace2 = go.Scatter3d(
x = cluster1["PC1_3d"],
y = cluster1["PC2_3d"],
z = cluster1["PC3_3d"],
mode = "markers",
name = "Cluster 1",
marker = dict(color = f'rgba(0, 0, 204, {trans})'),
text = None)
trace3 = go.Scatter3d(
x = cluster2["PC1_3d"],
y = cluster2["PC2_3d"],
z = …Run Code Online (Sandbox Code Playgroud) 我有一个数据框df:
x y z ... colours marker_size marker_opacity
test1 0.118709 0.219099 -0.024387 ... red 100 0.5
test2 -0.344873 -0.401508 0.169995 ... blue 100 0.5
test3 -0.226923 0.021078 0.400358 ... red 100 0.5
test4 0.085421 0.098442 -0.588749 ... purple 100 0.5
test5 0.367666 0.062889 0.042783 ... green 100 0.5
Run Code Online (Sandbox Code Playgroud)
我试图用这样的情节来绘制它:
fig = px.scatter_3d(df,
x='x', y='y', z = 'z',
color='labels',
hover_name = df.index,
opacity = 0.5,
size = 'marker_size')
fig.write_html(file_name)
Run Code Online (Sandbox Code Playgroud)
当我打开时file_name,一切都很好,但我的积分太大了。当我更改'marker_size'my 的列df时,没有任何变化(我尝试过 0.1、1、10、100...)。
为什么是这样? …
scatterplot3d在 R 中使用,我试图从观察到回归平面绘制红线:
wh <- iris$Species != "setosa"
x <- iris$Sepal.Width[wh]
y <- iris$Sepal.Length[wh]
z <- iris$Petal.Width[wh]
df <- data.frame(x, y, z)
LM <- lm(y ~ x + z, df)
library(scatterplot3d)
G <- scatterplot3d(x, z, y, highlight.3d = FALSE, type = "p")
G$plane3d(LM, draw_polygon = TRUE, draw_lines = FALSE)
Run Code Online (Sandbox Code Playgroud)
要获得下图的 3D 等效项:
在 2D 中,我可以使用segments:
pred <- predict(model)
segments(x, y, x, pred, col = 2)
Run Code Online (Sandbox Code Playgroud)
但是在 3D 中,我对坐标感到困惑。
我正在Google colab中生成3d散点图,但是问题是生成的无花果是静态的并且不能旋转。我也尝试了命令
%matplotlib笔记本
启用3D散射旋转,因为它显然在jupyter笔记本电脑环境中有效,但似乎在Google colab环境中不起作用。
你可以在这里找到我的代码
python data-visualization scatter-plot scatter3d google-colaboratory
我试图在 3D 散点图中可视化多个 2d 轨迹(x,y),其中 z 轴是时间。
import numpy as np
import pandas as pd
import plotly.express as px
# Sample data: 3 trajectories
t = np.linspace(0, 10, 200)
df = pd.concat([pd.DataFrame({'x': 900 * (1 + np.cos(t + 5 * i)), 'y': 400 * (1 + np.sin(t)), 't': t, 'id': f'id000{i}'}) for i in [0, 1, 2]])
# 3d scatter plot
fig = px.scatter_3d(df, x='x', y='y', z='t', color='id', )
fig.update_traces(marker=dict(size=2))
fig.show()
Run Code Online (Sandbox Code Playgroud)
我有一个 .png 地图文件,大小为:2000x1000。轨迹的 (x, y) 坐标对应于地图的像素位置。
我想在 3d 散点图的“地板”上看到地图的图像。 …
我正在使用 Python 中的 Plotly 显示昏暗缩减的词嵌入的一部分。我正在使用 3D 散点图,到目前为止一切正常,使用以下代码(已分解):
fig = go.Figure()
trace = go.Scatter3d(
x=df[0],
y=df[1],
z=df[2],
text=df.index,
mode="markers+text",
textfont=dict(
color=["crimson"]),
marker=dict(
size=3),
hoverinfo="skip")
fig.add_trace(trace)
fig.show()
Run Code Online (Sandbox Code Playgroud)
我遇到的唯一问题是数据点的某些标签重叠,这导致它们乍一看不可读。
是否可以指定文本标签的背景颜色?
编辑:
我的前 5 行df看起来像这样,所有数据都是这样构造的。索引是单词,三列是它在 3D 空间中的位置。
0 1 2
chancellor 1.102989 0.416767 2.071260
abdicate 0.028073 1.156498 1.911484
overthrow 2.435294 -0.305266 0.998094
candidate 0.259697 0.648845 0.448700
elections 0.122355 0.815206 1.107913
Run Code Online (Sandbox Code Playgroud)
然而,我的问题实际上并不是关于数据,而是关于定制可视化的可能性。
编辑2:
这就是我的情节。
正如您在左下角的簇中看到的,大多数标签相互重叠。我现在希望有一个隐藏参数可以用来使这些标签更好地可见,并且我本能地寻找一种方法为所有这些标签添加白色背景,这样就可以遮挡后面数据点的标签他们。
import plotly.graph_objects as go
import numpy as np
import numpy
# Download data set from plotly repo
pts = np.loadtxt(np.DataSource().open('https://raw.githubusercontent.com/plotly/datasets/master/mesh_dataset.txt'))
x, y, z = pts.T
US = [(1970, 4688.5), (1971, 4559.4), (1972, 4807.0), (1973, 4994.6), (1974, 4827.4), (1975, 4612.5), (1976, 4907.3),
(1977, 5071.4), (1978, 5066.2), (1979, 5105.1), (1980, 4877.4), (1981, 4808.0), (1982, 4562.2), (1983, 4541.5),
(1984, 4751.8), (1985, 4777.2), (1986, 4736.6), (1987, 4893.1), (1988, 5114.1), (1989, 5171.4), (1990, 5063.9),
(1991, 5022.3), (1992, 5103.5), (1993, 5222.5), (1994, 5305.7), (1995, 5357.6), (1996, …Run Code Online (Sandbox Code Playgroud) scatter3d ×10
plotly ×7
python ×6
r ×3
scatter-plot ×3
ggplot2 ×1
marker ×1
matplotlib ×1
r-plotly ×1
regression ×1
size ×1