我正在尝试自动更新散点图.我的X和Y值的来源是外部的,数据会以非预测的时间间隔(轮次)自动推送到我的代码中.
我只是设法在整个过程结束时绘制所有数据,而我正在尝试不断添加数据并将数据绘制到我的画布中.
我的代码的简化版本:
import matplotlib.pyplot as plt
def read_data():
#This function gets the values of xAxis and yAxis
xAxis = [some values] #these valuers change in each run
yAxis = [other values] #these valuers change in each run
plt.scatter(xAxis,yAxis, label = 'myPlot', color = 'k', s=50)
plt.xlabel('x')
plt.ylabel('y')
plt.show()
Run Code Online (Sandbox Code Playgroud) 我对 matplotlib 很陌生,我想知道如何根据列表中的值更改散点图上点的颜色。
事实上,我有一个要绘制的二维数组和一个行数相同的列表,其中每个点都包含我们要使用的颜色。
#Example
data = np.array([4.29488806,-5.34487081],
[3.63116248,-2.48616998],
[-0.56023222,-5.89586997],
[-0.51538502,-2.62569576],
[-4.08561754,-4.2870525 ],
[-0.80869722,10.12529582])
colors = ['red','red','red','blue','red','blue']
ax1.plot(data[:,0],data[:,1],'o',picker=True)
Run Code Online (Sandbox Code Playgroud)
如何设置颜色参数以适合我的颜色列表?
我想根据2个外部向量的值制作不同标记和不同颜色的图.
在这里我尝试过:
>>> s = [u'+', u'+', u'o']
>>> col = ['r','r','g']
>>> x = np.array([1,2,3])
>>> y = np.array([4,5,6])
>>> pl.scatter(x,y,marker=s,c=col)
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/matplotlib/markers.py", line 233, in set_marker
Path(marker)
File "/usr/lib/python3/dist-packages/matplotlib/path.py", line 133, in __init__
vertices = np.asarray(vertices, np.float_)
File "/usr/lib/python3/dist-packages/numpy/core/numeric.py", line 460, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: could not convert string to float: '+'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 ggplot2 创建一个对数间隔网格的图,如下图所示。我得到等距网格,但没有记录间隔网格。我知道我缺少一些我现在似乎没有得到的参数。我已经看到很多关于这个主题的问题,比如使用 ggplot2 (dynamic not manual) 对数正常刻度的漂亮刻度,但没有解决我正在寻找的问题。
set.seed(5)
x <- rlnorm(1000, meanlog=3.5, sdlog=1)
y <- rlnorm(1000, meanlog=4.0, sdlog=1)
d <- data.frame(x, y)
plot(x, y, log="xy", las=1)
grid(nx=NULL, ny=NULL, col= "blue", lty="dotted", equilogs=FALSE)
library(magicaxis)
magaxis(side=1:2, ratio=0.5, unlog=FALSE, labels=FALSE)
Run Code Online (Sandbox Code Playgroud)

library(ggplot2)
library(MASS)
library(scales)
a <- ggplot(d, aes(x=x, y=y)) + geom_point() +
scale_x_log10(limits = c(1, NA),
labels = trans_format("log10", math_format(10^.x)),
breaks=trans_breaks("log10", function(x) 10^x, n=4)) +
scale_y_log10(limits = c(1, NA),
labels = trans_format("log10", math_format(10^.x)),
breaks=trans_breaks("log10", function(x) 10^x, n=4)) +
theme_bw() + theme(panel.grid.minor …Run Code Online (Sandbox Code Playgroud) 我尝试使用下面的代码生成,将有斜体的相关系数简单的散点图[R置于情节.
data(mtcars)
# Load required libraries
require(ggplot2) # To derive the graphs
require(ggthemes) # To apply ggplot themes to the chart
require(scales) # For pretty breaks
# Function to generate correlation coefficient for the charts
corr_eqn <- function(x,y, digits = 2) {
corr_coef <- round(cor(x, y), digits = digits)
corr_coef <- expression(paste(italic(r)," = ", corr_coef))
return(corr_coef)
}
# Provide a scatter plot for income and health deprivation
ggplot(mtcars, aes(x = drat, y = wt)) +
geom_point(shape = 19, …Run Code Online (Sandbox Code Playgroud) 我想生成一个pandas DataFrame的散点图,其中包含分类行和列标签matplotlib.示例DataFrame如下所示:
import pandas as pd
df = pd.DataFrame({"a": [1,2], "b": [3,4]}, index=["c","d"])
# a b
#c 1 2
#d 3 4
Run Code Online (Sandbox Code Playgroud)
标记大小是相应DataFrame值的函数.到目前为止,我提出了一个尴尬的解决方案,基本上枚举行和列,绘制数据,然后重建标签:
flat = df.reset_index(drop=True).T.reset_index(drop=True).T.stack().reset_index()
# level_0 level_1 0
#0 0 0 1
#1 0 1 2
#2 1 0 3
#3 1 1 4
flat.plot(kind='scatter', x='level_0', y='level_1', s=100*flat[0])
plt.xticks(range(df.shape[1]), df.columns)
plt.yticks(range(df.shape[0]), df.index)
plt.show()
Run Code Online (Sandbox Code Playgroud)
现在,问题:是否有更直观,更集成的方法来生成此散点图,理想情况下不分割数据和元数据?
我正在尝试使用ggplot绘制一些数据,并且我对重要的行和星号有一些问题.
这是我正在使用的代码:
p <- ggplot(Hematoxilin_tumor_necrosis, aes(x=total, y=necro, colour = Group))+
labs(y="Necrotic area",x="Total area")+
theme_minimal()
path = data.frame(x=c(78,79,79,78),y=c(22,22,34,34))
p + geom_point(size=0.7)+
geom_smooth(method=lm, se = F, size=0.8) +
scale_color_manual(values=c("#999999","#333333"))+
#Adding asterisks
geom_path(data = path, aes(x = x,y = y)) +
annotate("text",x = 80, y = 27, label="*", cex=7)
Run Code Online (Sandbox Code Playgroud)
这给了我以下错误:
FUN中的错误(X [[i]],...):找不到对象'组'
我知道问题出在了,geom_path(data = path, aes(x = x,y = y))但我有点迷茫.我是ggplot的新手,所以我期待一些简单的问题.
有什么建议?
我有一套要点:
a = ([126, 237, 116, 15, 136, 348, 227, 247, 106, 5, -96, 25, 146], [117, 127, 228, 107, 6, 137, 238, 16, 339, 218, 97, -4, -105])
Run Code Online (Sandbox Code Playgroud)
我像这样制作一个散点图:
fig = plt.figure(figsize = (15,6))
ax = fig.add_subplot(111)
ax.scatter(a[0], a[1], color = 'red', s=binradius)
Run Code Online (Sandbox Code Playgroud)
这使得这个情节:
-
我将其与图片重叠,其中每个散点处都有一个球形斑点.我想要适合这个blob,所以我在散点周围定义了一个矩形区域,以便进行拟合.
我想在图上看到这个矩形,以便在视觉上看它们是否足够大以包围blob,如下所示:
我能用scatter吗?或者还有其他方法可以做到吗?
是否可以向a添加多个数据pandas.tools.plotting.scatter_matrix并为每组数据指定颜色?
我想用一组数据显示带有数据点的散点图,比如绿色,另一组用红色表示相同的散布矩阵.同样适用于对角线上的密度图.我知道这可以通过使用matplotlib的scatter函数来实现,但这并没有给我一个散点矩阵.
大熊猫的文件很清楚.
scatter-plot ×10
python ×7
matplotlib ×5
ggplot2 ×3
r ×3
pandas ×2
annotations ×1
bokeh ×1
colormap ×1
dataframe ×1
expression ×1
r-grid ×1