我正在尝试在R中实现三次样条函数.我已经使用了R库中可用的样条曲线,smooth.spline和smooth.Pspline函数,但我对结果并不满意所以我想说服自己通过"自制"样条函数得出结果的一致性.我已经计算了三次多项式的系数,但我不知道如何绘制结果......它们似乎是随机点.您可以在下面找到源代码.任何帮助,将不胜感激.
x = c(35,36,39,42,45,48)
y = c(2.87671519825595, 4.04868309245341, 3.95202175000174,
3.87683188946186, 4.07739945984612, 2.16064840967985)
n = length(x)
#determine width of intervals
h=0
for (i in 1:(n-1)){
h[i] = (x[i+1] - x[i])
}
A = 0
B = 0
C = 0
D = 0
#determine the matrix influence coefficients for the natural spline
for (i in 2:(n-1)){
j = i-1
D[j] = 2*(h[i-1] + h[i])
A[j] = h[i]
B[j] = h[i-1]
}
#determine the constant matrix C
for (i in 2:(n-1)){
j …Run Code Online (Sandbox Code Playgroud) 我想使用axis()在图的上方和右侧创建一个带有刻度和标签的图。如何抑制使用 plot() 函数“自动”打印的刻度和标签?谢谢
x<-1:10
y<-1:10
quartz("test")
par(mar=c(10,10,10,10)+0.1)#sets margins of plotting area
par(pty="s")#fixes the aspect ratio to 1:1
#Automatically adds ticks, numbers and axis labels. How can I avoid this?
plot(x,y,typ="n")
#Adds axes above and to the right of plot area...I want these only
axis(side=4,las=2, ylab="y label")
axis(side=3,las=1,xlab="x label")
Run Code Online (Sandbox Code Playgroud) 我有一个带有一些图的脚本(参见示例代码).在其他一些事情之后,我想为现有的一个添加一个新的情节.但是,当我尝试它添加最后创建的数字(现在图2)的情节.我无法弄清楚如何改变......
import matplotlib.pylab as plt
import numpy as np
n = 10
x1 = np.arange(n)
y1 = np.arange(n)
fig1 = plt.figure()
ax1 = fig1.add_subplot(111)
ax1.plot(x1,y1)
fig1.show()
x2 = np.arange(10)
y2 = n/x2
# add new data and create new figure
fig2 = plt.figure()
ax2 = fig2.add_subplot(111)
ax2.plot(x2,y2)
fig2.show()
# do something with data to compare with new data
y1_geq = y1 >= y2
y1_a = y1**2
ax1.plot(y1_geq.nonzero()[0],y1[y1_geq],'ro')
fig1.canvas.draw
Run Code Online (Sandbox Code Playgroud) 我在Seaborn热图中存储标签时遇到问题.我拥有的标签很长.当我plt.show()用来显示我的情节时,我可以通过调整画布大小来查看完整标签.但是,当我保存到文件时,只存储标签的一小部分.我在Seaborn中使用了以下代码0.7.1:
ax = sns.heatmap(some_matrix)
ax.set_yticklabels(labels=some_labels,rotation=0)
fig = ax.get_figure()
fig.savefig("my_file.png",dpi=600)
Run Code Online (Sandbox Code Playgroud)
任何线索我如何增加画布的大小,以便完整的标签存储在我的.png文件中?减小字体大小可能不是一个好的解决方案,因为Y轴上有很多标签,导致标签变得不可读.
我需要使用 ggplot 绘制不同日期的每小时数据,这是我的数据集:
数据由每小时观察组成,我想将每天的观察绘制成单独的一行。
这是我的代码
xbj1 = bj[c(1:24),c(1,6)]
Run Code Online (Sandbox Code Playgroud)
xbj2 = bj[c(24:47),c(1,6)]
xbj3 = bj[c(48:71),c(1,6)]
ggplot()+
geom_line(data = xbj1,aes(x = Date, y= Value), colour="blue") +
geom_line(data = xbj2,aes(x = Date, y= Value), colour = "grey") +
geom_line(data = xbj3,aes(x = Date, y= Value), colour = "green") +
xlab('Hour') +
ylab('PM2.5')
Run Code Online (Sandbox Code Playgroud)
请就此提出建议。
Stephen Few最近推出了Bandlines,这是Edward Tufte的Sparklines的延伸.有没有一种简单的方法来使用ggplot2生成这些类型的图?
我有深度与时间的关系:
这个情节在5月初有一个奇怪的差距.

我检查了数据,但没有NAs或Nans或没有丢失的数据.这是15分钟的定期间隔的时间序列
我不能在这里给出数据集,因为它包含10,000行.有人可以提出可能的建议吗?
我使用以下绘图代码:
library(zoo)
z=read.zoo("data.txt", header=TRUE)
temp=index(z[,1])
m=coredata(z[,1])
x=0.001
p=rep.int(x,length(temp))
png(filename=paste(Name[k],"_mean1.png", sep=''), width= 3500, height=1600, units="px")
par(mar=c(13,13,5,3),cex.axis= 2.5, cex.lab=3, cex.main=3.5, cex.sub=5)
plot(temp,m, xlab="Time", ylab="Depth",type='l', main=Name[k])
symbols(temp,m,add=TRUE,circles=p, inches=1/15, ann=F, bg="steelblue2", fg=NULL)
dev.off()
Run Code Online (Sandbox Code Playgroud) 我有9组患者的经验数据,数据以这种格式显示
input = [10 -1 1
20 17956 1
30 61096 1
40 31098 1
50 18446 1
60 12969 1
95 7932 1
120 6213 1
188 4414 1
240 3310 1
300 3329 1
610 2623 1
1200 1953 1
1800 1617 1
2490 1559 1
3000 1561 1
3635 1574 1
4205 1438 1
4788 1448 1
];
calibrationfactor_wellcounter =1.841201569;
Run Code Online (Sandbox Code Playgroud)
这里,第一列描述时间值,下一列是浓度.如您所见,浓度会增加一段时间,然后随着时间的增加呈指数下降.
如果我绘制以下特征,我获得以下曲线
我想创建一个代表上面引用的相同行为的脚本.以下是我制定的脚本,其中浓度线性增加直到某个时间段和后果它以指数方式衰减,但是当我绘制此函数我获得线性特征时,请告诉我我的逻辑是否合适
function c_o = Sample_function(td,t_max,a1,a2,a3,b1,b2,b3)
t =(0: 100 :5000); % time of the sample post …Run Code Online (Sandbox Code Playgroud) 我有两个从机器学习计算得到的数组x,y,我希望在对角线上用参考数据x制作一个散点图,以便更好地将预测值y与真实的x进行可视化.请问你能告诉我如何在python或gnuplot中做到这一点吗?
plot ×10
r ×6
matplotlib ×3
python ×3
ggplot2 ×2
graphics ×2
cubic ×1
curve ×1
exponential ×1
matlab ×1
scatter ×1
seaborn ×1
sparklines ×1
spline ×1
time-series ×1