用等距(弧长)标记绘制曲线 [英] Plotting a curve with equidistant (arc-length) markers

查看:117
本文介绍了用等距(弧长)标记绘制曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制一些实验数据的图,这些数据以相对较高的速率采样,但是使用等距弧长间隔的标记近似平滑曲线,如下图所示:

I would like to plot a graph of some experimental data which is sampled at a relatively high rate, but approximates a smooth curve using markers spaced at equal arc-length intervals as shown in the graph below:

我知道plot的markevery参数,但是这会使图表右侧的标记堆积很多,而左侧的标记可能很少.解应独立于x和y轴上的比例.我愿意安装其他模块,但这应该是python + matplotlib解决方案.

I know about the markevery argument to plot, but that would bunch up the markers to the right of the plot and probably have quite few markers on the left. The solution should be independent of the scales on the x and y axes. I am open to installing additional modules, but it should be a python+matplotlib solution.

推荐答案

从matplotlib 1.4开始,您可以将markevery与实数结合使用以实现此目的.

Since matplotlib 1.4, you can use markevery with real numbers to achieve this.

文档: http://matplotlib.org/api/lines_api. html#matplotlib.lines.Line2D.set_markevery

示例:

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 10*np.pi, 1000)
y = np.sin(x*2) + np.sin(x + 1)

plt.plot(x, y, marker='o', markevery=0.05)

plt.show()

这篇关于用等距(弧长)标记绘制曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆