我正在使用Python和CSV文件.我目前正在尝试修改下面的散点图(2d),以根据我的csv文件中的第三列更改颜色.在搜索多个帖子之后,我基本上想要使用通用色图(彩虹)并将第三个数组乘以色彩图,以便为每个xy点显示不同的颜色.我想我可以从ax.scatter函数中做所有事情,但我不知道如何将每个不同的x,y坐标乘以色图和第三个数组.它应该看起来类似于等高线图,但我更喜欢不同颜色的散点图.
这是我正在使用的代码:
import matplotlib
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
import matplotlib.mlab as mlab
import numpy as np
r = mlab.csv2rec('test.csv')
fig = Figure(figsize=(6,6))
canvas = FigureCanvas(fig)
ax = fig.add_subplot(111)
ax.set_title("X vs Y AVG",fontsize=14)
ax.set_xlabel("XAVG",fontsize=12)
ax.set_ylabel("YAVG",fontsize=12)
ax.grid(True,linestyle='-',color='0.75')
x = r.xavg #first column
y = r.yavg #second column
z = r.wtr #third column
ax.scatter(x,y,s=.2,c='b', marker = ',', cmap = ?);
Run Code Online (Sandbox Code Playgroud) 我想用ggplot2生成一个散点图,它包含所有数据点的回归线(无论它们来自哪个组),但同时通过分组变量改变标记的形状.下面的代码生成组标记,但提出了两个回归线,每组一个.
#model=lm(df, ParamY~ParamX)
p1<-ggplot(df,aes(x=ParamX,y=ParamY,shape=group)) + geom_point() + stat_smooth(method=lm)
Run Code Online (Sandbox Code Playgroud)
我该怎么编程呢?
我需要绘制几个定义为的数据点
c(x,y,stdev_x,stdev_y)
作为具有95%置信限的表示的散点图,示例显示了点和围绕它的一个轮廓.理想情况下,我想在点周围绘制椭圆形,但不知道该怎么做.我正在考虑构建样本并绘制它们,添加stat_density2d()但是需要将轮廓数量限制为1,并且无法弄清楚如何去做.
require(ggplot2)
n=10000
d <- data.frame(id=rep("A", n),
se=rnorm(n, 0.18,0.02),
sp=rnorm(n, 0.79,0.06) )
g <- ggplot (d, aes(se,sp)) +
scale_x_continuous(limits=c(0,1))+
scale_y_continuous(limits=c(0,1)) +
theme(aspect.ratio=0.6)
g + geom_point(alpha=I(1/50)) +
stat_density2d()
Run Code Online (Sandbox Code Playgroud) 我正在尝试绘制3D散射matplotlib
问题是我无法更改标记的大小我有这个
scat = plt.scatter([boid_.pos[0] for boid_ in flock],
[boid_.pos[1] for boid_ in flock],
[boid_.pos[2] for boid_ in flock],
marker='o', s=5)
Run Code Online (Sandbox Code Playgroud)
但是我得到了错误
TypeError: scatter() got multiple values for keyword argument 's'
Run Code Online (Sandbox Code Playgroud)
没有它,情节工作正常.问题出在哪儿?还是有另一种方法来改变大小?
我试图绘制一个像这样的简单散点图:

我用于生成此图的最小代码如下:
ggplot(fig1c, aes(x=xvar, y=yvar)) +
scale_x_log10(breaks=unique(fig1c$xvar)) +
scale_y_continuous(breaks=seq(0, 10, by=1), labels=as.character(seq(0, 10, by=1))) +
geom_point(aes(fill=Method, color=Method, shape=Method), size = 5, guides=FALSE) +
scale_colour_brewer(palette="Set1") +
geom_line(aes(fill=Method, color=Method)) +
Run Code Online (Sandbox Code Playgroud)
我想要实现的是让x轴上的所有点(5884,13957,...)等间距.即我希望点5884和13957之间的间隔与13957和21013之间的大小相同,依此类推.有帮助吗?
谢谢
我目前正在根据两列数据绘制散点图.但是,我想基于第三列中的类标签为数据点着色.
我的第三列中的标签是1,2或3.我如何根据第三列中的值为散点图颜色着色?
plt.scatter(waterUsage['duration'],waterUsage['water_amount'])
plt.xlabel('Duration (seconds)')
plt.ylabel('Water (gallons)')
Run Code Online (Sandbox Code Playgroud) 更新10/3/2018:这不是R独有的.它之前已被报道,目前被标记为功能请求,在这里:https://github.com/plotly/plotly.js/issues/260
我正在为r中的plotly图形添加散点图点的自定义悬停文本.它似乎是将文本左对齐,居中对齐或右对齐,具体取决于文本框是分别显示在绘图点的右侧,中间还是左侧.无论盒子的位置如何,我都希望文本始终对齐.我已经能够设置字体样式,例如设置颜色和大小,但无法更改文本对齐方式.
这是一个MRE.我删除了传说,所以最右边的点被迫让他们的悬停框出现在点的左边.
plot_ly(iris,
x = ~Sepal.Length,
y = ~Sepal.Width,
type = 'scatter',
mode = 'markers',
hoverinfo = 'text',
hoverlabel = list(font = list(color = 'white')),
text = ~paste0('Some rather long text',
'\nSepal.Length: ', Sepal.Length,
'\nSepal.Width: ', Sepal.Width)) %>%
layout(showlegend = FALSE)
Run Code Online (Sandbox Code Playgroud)
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 中,我对坐标感到困惑。
我试图将 Pandas 列中的数据可视化为 3D 散点图。我面临的问题是将颜色条匹配调整到我的 z 轴的确切大小。
我的代码:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
s = pd.read_csv('FahrerVP8.out_1.csv', index_col=0)
ax = plt.figure()
three_d = ax.gca(projection='3d')
three_d1 = three_d.scatter(s['Latitude'], s['Longitude'],s['Mean_ VehicleSpeed'], c =s['Mean_ VehicleSpeed'] )
three_d.set_xlabel('Latitude')
three_d.set_ylabel('Longitude')
three_d.set_zlabel('Mean Vehicle Speed')
plt.colorbar(three_d1)
plt.show()
Run Code Online (Sandbox Code Playgroud)
我的结果
我希望用 z 轴高度调整我的彩条高度。
我正在尝试使用seaborn散点图的顺序颜色啤酒调色板,但它无法正常工作。这就是我到目前为止所做的。我将不胜感激任何帮助。
import seaborn as sns
from random import randrange
y = [randrange(100) for i in range(50)]
x = [i for i in range(50)]
ax = sns.scatterplot(x=x, y=y, s=15, c=y, palette=sns.color_palette("YlOrBr", as_cmap=True))
Run Code Online (Sandbox Code Playgroud)
scatter-plot ×10
python ×5
r ×5
matplotlib ×4
ggplot2 ×3
csv ×1
hover ×1
numpy ×1
pandas ×1
plotly ×1
python-3.x ×1
r-plotly ×1
regression ×1
scatter3d ×1
seaborn ×1
size ×1