标签: scatter-plot

How to disable legend in nvd3 or limit it's size

I'm using nvd3 and have a few charts where the legend is much to large. E.g. a scatter/bubble with 15 groups and the group names are long. The legend is so large that it leaves almost no room for the chart itself.

Is there a way to remove the legend or toggle the legend or limit the height/width it is taking up? Any example would be great.

Also, is there a way to have the bubble show a descriptive string? …

bubble-chart legend scatter-plot d3.js nvd3.js

20
推荐指数
1
解决办法
2万
查看次数

使用pyplot在python中绘制多个子图上的水平线

我正在同一页面上绘制三个子图.我想在所有子图中绘制一条horiZontal线.以下是我的代码和结果图:(您可以注意到我可以在其中一个图上获得水平线,但不是全部)

gs1 = gridspec.GridSpec(8, 2)
gs1.update(left=0.12, right=.94, wspace=0.12)
ax1 = plt.subplot(gs1[0:2, :])
ax2 = plt.subplot(gs1[3:5, :], sharey=ax1)
ax3 = plt.subplot(gs1[6:8, :], sharey=ax1)

ax1.scatter(theta_cord, density, c = 'r', marker= '1')
ax2.scatter(phi_cord, density, c = 'r', marker= '1')
ax3.scatter(r_cord, density, c = 'r', marker= '1')
ax1.set_xlabel('Theta (radians)')
ax1.set_ylabel('Galaxy count')
ax2.set_xlabel('Phi (radians)')
ax2.set_ylabel('Galaxy count')
ax3.set_xlabel('Distance (Mpc)')
ax3.set_ylabel('Galaxy count')
plt.ylim((0,0.004))
loc = plticker.MultipleLocator(base=0.001)
ax1.yaxis.set_major_locator(loc)

plt.axhline(y=0.002, xmin=0, xmax=1, hold=None)

plt.show()
Run Code Online (Sandbox Code Playgroud)

这会生成以下内容: 在此输入图像描述

同样,我希望我在最后一个子图上绘制的线也出现在前两个子图上.我怎么做?

python matplotlib scatter-plot subplot line-plot

20
推荐指数
2
解决办法
5万
查看次数

python中的多变量(多项式)最佳拟合曲线?

你如何计算python中的最佳拟合线,然后在matplotlib的散点图上绘制它?

我是使用普通最小二乘回归计算线性最佳拟合线,如下所示:

from sklearn import linear_model
clf = linear_model.LinearRegression()
x = [[t.x1,t.x2,t.x3,t.x4,t.x5] for t in self.trainingTexts]
y = [t.human_rating for t in self.trainingTexts]
clf.fit(x,y)
regress_coefs = clf.coef_
regress_intercept = clf.intercept_      
Run Code Online (Sandbox Code Playgroud)

这是多变量的(每种情况都有很多x值).因此,X是列表列表,y是单个列表.例如:

x = [[1,2,3,4,5], [2,2,4,4,5], [2,2,4,4,1]] 
y = [1,2,3,4,5]
Run Code Online (Sandbox Code Playgroud)

但是我如何使用高阶多项式函数来做到这一点.例如,不仅是线性(x到M = 1的幂),而是二项式(x到M = 2的幂),二次方(x到M = 4的幂),依此类推.例如,如何从以下获得最佳拟合曲线?

摘自Christopher Bishops的"模式识别与机器学习",第7页:

摘自Christopher Bishops的

python regression machine-learning matplotlib scatter-plot

19
推荐指数
1
解决办法
3万
查看次数

制作散射轮廓

在python中,如果我有一组数据

x, y, z
Run Code Online (Sandbox Code Playgroud)

我可以散布

import matplotlib.pyplot as plt
plt.scatter(x,y,c=z)
Run Code Online (Sandbox Code Playgroud)

我如何得到plt.contourf(x,y,z)分散?

python matplotlib scatter-plot contour

19
推荐指数
3
解决办法
2万
查看次数

用rg中的ggplot2中的线连接点

这是我的数据:

    mydata <- data.frame (grp = c(  1,   1,   1,  1, 1,  1, 1, 1, 1, 
     2,2, 2, 2,2, 2, 2, 2, 2),
    grp1 = c("A", "A", "A", "A", "A",  "B", "B", "B", "B" ,  
    "A", "A", "A", "A",      "B", "B", "B", "B", "B"), 
   namef = c("M1", "M3", "M2", "M4", "M5","M1", "M3", "M4", 
    "M0", "M6", "M7", "M8",       "M10", "M6", "M7", "M8", "M9", "M10"),
     dgp = c(1, 1, 1, 1, 1,  1.15, 1.15,1.15, 1.15 ,
        2, 2, 2, 2,2.15, 2.15, 2.15, …
Run Code Online (Sandbox Code Playgroud)

r line scatter-plot segment ggplot2

18
推荐指数
1
解决办法
3万
查看次数

如果我没有跟踪进入的所有数据点,则将y = x添加到matplotlib散点图中

这里有一些代码使用matplotlib散布了许多不同系列的图,然后添加了行y = x:

import numpy as np, matplotlib.pyplot as plt, matplotlib.cm as cm, pylab

nseries = 10
colors = cm.rainbow(np.linspace(0, 1, nseries))

all_x = []
all_y = []
for i in range(nseries):
    x = np.random.random(12)+i/10.0
    y = np.random.random(12)+i/5.0
    plt.scatter(x, y, color=colors[i])
    all_x.extend(x)
    all_y.extend(y)

# Could I somehow do the next part (add identity_line) if I haven't been keeping track of all the x and y values I've seen?
identity_line = np.linspace(max(min(all_x), min(all_y)),
                            min(max(all_x), max(all_y)))
plt.plot(identity_line, identity_line, color="black", linestyle="dashed", linewidth=3.0)

plt.show() …
Run Code Online (Sandbox Code Playgroud)

python plot matplotlib scatter-plot

16
推荐指数
4
解决办法
2万
查看次数

在ggpairs中操纵轴标题(GGally)

我正在使用下面的代码生成以下图表.

# Setup
data(airquality)

# Device start
png(filename = "example.png", units = "cm", width = 20, height = 14, res = 300)

# Define chart
pairs.chrt <- ggpairs(airquality,
                      lower = list(continuous = "smooth"),
                      diag = list(continuous = "blank"),
                      upper = list(continuous = "blank")) +
  theme(legend.position = "none",
        panel.grid.major = element_blank(),
        axis.ticks = element_blank(),
        axis.title.x = element_text(angle = 180, vjust = 1, color = "black"),
        panel.border = element_rect(fill = NA))

# Device off and print
print(pairs.chrt)
dev.off()
Run Code Online (Sandbox Code Playgroud)

ggpairs  - 第一个例子

我目前正在尝试修改轴标题的显示.特别是,我希望轴标题是:

  1. 放置在距离轴标签更远的位置 …

r scatter-plot ggally r-corrplot

15
推荐指数
2
解决办法
9963
查看次数

matplotlib scatter 失败并出现错误:'c' 参数有 n 个元素,这对于大小为 n 的 'x'、大小为 n 的 'y' 来说是不可接受的

我正在尝试使用 matplotlib 创建一个散点图,其中每个点都有一个特定的颜色值。

我缩放这些值,然后在“左”和“右”颜色之间应用 alpha 混合。

# initialization
from matplotlib import pyplot as plt
from sklearn.preprocessing import MinMaxScaler
import numpy as np

values = np.random.rand(1134)

# actual code
colorLeft = np.array([112, 224, 112])
colorRight = np.array([224, 112, 112])
scaled = MinMaxScaler().fit_transform(values.reshape(-1, 1))
colors = np.array([a * colorRight + (1 - a) * colorLeft for a in scaled], dtype = np.int64)
# check values here
f, [sc, other] = plt.subplots(1, 2)
sc.scatter(np.arange(len(values)), values, c = colors)
Run Code Online (Sandbox Code Playgroud)

但是最后一行给出了错误:

'c' 参数有 1134 个元素,不能用于大小为 …

python matplotlib scatter-plot

15
推荐指数
1
解决办法
2万
查看次数

使用matplotlib在xy散点图中的错误栏的Colormap

我有一个时间序列的数据,我有数量,y和它的错误,yerr.我现在想创建一个图表,显示y与相位(即时间/周期%1)和垂直错误栏(yerr).为此,我通常使用pyplot.errorbar(time,y,yerr = yerr,...)

但是,我想使用颜色条/贴图来指示同一图中的时间值.

我这样做的是以下几点:

pylab.errorbar( phase, y, yerr=err, fmt=None, marker=None, mew=0 )
pylab.scatter( phase, y, c=time, cmap=cm )
Run Code Online (Sandbox Code Playgroud)

不幸的是,这将绘制单色错误栏(默认为蓝色).由于每个绘图有大约1600个点,这使得散点图的色图在误差条后面消失.这是一张图片显示我的意思:

在此输入图像描述

有没有办法让我可以使用与散点图中使用的色彩图相同的色彩图来绘制误差线?我不想调用错误栏1600次...

python matplotlib scatter-plot color-mapping

14
推荐指数
4
解决办法
9793
查看次数

非参数分位数回归曲线到散点图

我创建了一个散点图(多组GRP)用IV=time,DV=concentration.我想在(0.025,0.05,0.5,0.95,0.975)我的情节中添加分位数回归曲线.

顺便说一句,这就是我创建散点图的方法:

attach(E)  ## E is the name I gave to my data
## Change Group to factor so that may work with levels in the legend
Group<-as.character(Group)
Group<-as.factor(Group)

## Make the colored scatter-plot
mycolors = c('red','orange','green','cornflowerblue')
plot(Time,Concentration,main="Template",xlab="Time",ylab="Concentration",pch=18,col=mycolors[Group])

## This also works identically
## with(E,plot(Time,Concentration,col=mycolors[Group],main="Template",xlab="Time",ylab="Concentration",pch=18))

## Use identify to identify each point by group number (to check)
## identify(Time,Concentration,col=mycolors[Group],labels=Group)
## Press Esc or press Stop to stop identify function

## Create legend
## Use …
Run Code Online (Sandbox Code Playgroud)

regression r scatter-plot quantile

14
推荐指数
2
解决办法
3182
查看次数