我有以下简单的脚本绘制图表:
import matplotlib.pyplot as plt
import numpy as np
T = np.array([6, 7, 8, 9, 10, 11, 12])
power = np.array([1.53E+03, 5.92E+02, 2.04E+02, 7.24E+01, 2.72E+01, 1.10E+01, 4.70E+00])
plt.plot(T,power)
plt.show()
Run Code Online (Sandbox Code Playgroud)
就像现在一样,这条直线从一点到另一点直线看起来不错,但在我看来可能更好.我想要的是平滑点之间的界限.在Gnuplot,我会用smooth cplines.
在PyPlot中有一种简单的方法吗?我找到了一些教程,但它们看起来都相当复杂.
我正在从测量距离的设备上读取数据.我的采样率很高,因此我可以测量距离(即速度)的较大变化,但这意味着,当速度较低时,设备会提供相同的多个测量值(由于设备的粒度).这导致"阶梯"曲线.
我需要做的是平滑曲线以计算速度.然后,我需要计算加速度.
如何最好地解决这个问题?
(采样率高达1000Hz,计算速率为10Hz即可.在VS2005中使用C#)
可能重复:
iPhone平滑的草图绘制算法
我想开发一个支持草图绘制的iPhone应用程序.
我在touchesMoved中使用了这样的代码:
UIGraphicsBeginImageContext(self.view.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 1.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), points.pointB.x, points.pointB.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), points.pointA.x, points.pointA.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)
看到:

曲线不够平滑.
我尝试过使用catforge.net/project /curve/files
看到:

这次曲线更平滑但有2个问题:
Catmull-Rom Spline使用许多三次贝塞尔曲线段和二次贝塞尔曲线段来形成曲线.当触摸结束时,不能确定二次贝塞尔曲线段.在用户将手指从屏幕上移开之前,我无法绘制二次线段.我只能在用户绘图时绘制立方体段,这样他会感到有些延迟.当手指快速移动时,曲线滞后于手指.
该算法过多地校正了角落,因此用户无法绘制具有尖角的星形.
我非常希望为用户提供非常好的绘图环境,例如Autodesk的"Sketch Book"应用程序.(见下图)
看到:

该应用程序提供平滑的曲线,它还允许我绘制一个尖角的星.
我怎么能在iPhone上这样做?我可以使用哪种算法来实现"Sketch Book"这样的高质量?我的参考代码?
谢谢!!
我正在处理用户行为项目.根据用户交互,我得到了一些数据.有一个很好的序列,随着时间的推移平稳地增加和减少.但是差异很小,非常糟糕.请参考下图:

你也可以在这里找到数据:
2.0789 2.09604 2.11472 2.13414 2.15609 2.17776 2.2021 2.22722 2.25019 2.27304 2.29724 2.31991 2.34285 2.36569 2.38682 2.40634 2.42068 2.43947 2.45099 2.46564 2.48385 2.49747 2.49031 2.51458 2.5149 2.52632 2.54689 2.56077 2.57821 2.57877 2.59104 2.57625 2.55987 2.5694 2.56244 2.56599 2.54696 2.52479 2.50345 2.48306 2.50934 2.4512 2.43586 2.40664 2.38721 2.3816 2.36415 2.33408 2.31225 2.28801 2.26583 2.24054 2.2135 2.19678 2.16366 2.13945 2.11102 2.08389 2.05533 2.02899 2.00373 1.9752 1.94862 1.91982 1.89125 1.86307 1.83539 1.80641 1.77946 1.75333 1.72765 1.70417 1.68106 1.65971 1.64032 1.62386 1.6034 1.5829 …
在Android中用手指在触摸屏上绘图时,如何获得平滑曲线而不是圆点或圆圈?我使用以下代码 -
public class DrawView extends View implements OnTouchListener {
private static final String TAG = "DrawView";
List<Point> points = new ArrayList<Point>();
Paint paint = new Paint();
public DrawView(Context context) {
super(context);
setFocusable(true);
setFocusableInTouchMode(true);
this.setOnTouchListener(this);
paint.setColor(Color.WHITE);
paint.setAntiAlias(true);
}
@Override
public void onDraw(Canvas canvas) {
for (Point point : points) {
canvas.drawCircle(point.x, point.y, 5, paint);
// Log.d(TAG, "Painting: "+point);
}
}
public boolean onTouch(View view, MotionEvent event) {
// if(event.getAction() != MotionEvent.ACTION_DOWN)
// return super.onTouchEvent(event);
Point point = new Point();
point.x …Run Code Online (Sandbox Code Playgroud) 我正在使用Mathematica 7.
我有一个插值函数,这是一个例子:
pressures =
WeatherData["Chicago", "Pressure", {2010, 8}] //
DeleteCases[#, {_, _Missing}] & //
Map[{AbsoluteTime[#[[1]]], #[[2]]} &, #] & // Interpolation;
Run Code Online (Sandbox Code Playgroud)
我想计算它的衍生物,这是直截了当的:
dpressures = D[pressures[x], x]
Run Code Online (Sandbox Code Playgroud)
现在,如果你绘制这个功能
Plot[3600*dpressures, {x, AbsoluteTime[{2010, 8, 2}], AbsoluteTime[{2010, 8, 30}]}]
Run Code Online (Sandbox Code Playgroud)
(抱歉,不知道如何从Mathematica中发布图像,并且没有时间弄明白.)你会发现它非常嘈杂.所以,我想说清楚它.我的第一个想法是使用Convolve,并将其与高斯内核集成,如下所示:
a = Convolve[PDF[NormalDistribution[0, 5], x], 3600*dpressures, x, y]
Run Code Online (Sandbox Code Playgroud)
返回
360 Sqrt[2/\[Pi]] Convolve[E^(-(x^2/50)), InterpolatingFunction[{{3.48961266 10^9, 3.49228746 10^9}},<>], ][x], x, y]
Run Code Online (Sandbox Code Playgroud)
这对我来说看起来很合理.不幸的是,我相信我在某个地方犯了一个错误,因为我回来的结果似乎不是可评估的.那是:
a /. y -> AbsoluteTime[{2010, 8, 2}]
Run Code Online (Sandbox Code Playgroud)
返回
360 Sqrt[2/\[Pi]] Convolve[E^(-(x^2/50)), InterpolatingFunction[{{3.48961266 10^9, 3.49228746 10^9}},<>][x], x, 3489696000]]
Run Code Online (Sandbox Code Playgroud)
这不是我想要的东西我期待-1到1之间的数字.
data <- dput(data): structure(list(x = 1:16, y = c(-79.62962963, -84.72222222, -88.42592593, -74.07407407, -29.62962963, 51.38888889, 79.62962963, 96.2962963, 87.96296296, 88.42592593, 73.14814815, 12.96296296, -63.42592593, -87.03703704, -87.5, -87.96296296)), .Names = c("x", "y"), row.names = c(NA, 16L), class = "data.frame")
Run Code Online (Sandbox Code Playgroud)
我在R中用ggplot2计算了我的数据集的平滑线:
p1 <- ggplot(data, aes(x=x(°), y=(%)))
library(splines)
library(MASS)
(p2 <- p1 + stat_smooth(method = "lm", formula = y ~ ns(x,3)) +
geom_point()
)
Run Code Online (Sandbox Code Playgroud)
如何计算平滑线曲线最大值的x值?