matplotlib中的词干图? [英] Stem plot in matplotlib?

查看:30
本文介绍了matplotlib中的词干图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想 plot(x, sin(x)) 但不是从 (xi,yi)(x_i+1,y_i+1)我想要从(xi,0)(xi,yi)的每个点都有一条垂直线,因为有时点之间的插值没有意义(例如量化数据)(使用垂直线看起来要比不使用垂直线要好得多).

I want to plot(x, sin(x)) but instead of a line from (xi,yi) to (x_i+1,y_i+1) I want a vertical line to each point from (xi,0) to (xi,yi) as sometimes interpolation between the points makes no sense (e.g. quantized data) (and it looks much better with that vertical line than without).

与下面的词干图非常相似(来自Matlab文档),但可以关闭圆和点之间的-"选项.不幸的是,我本人在matplotlib文档中找不到合适的绘图功能.

Much like the stem plot below (from the matlab docs) but with the option of being able to turn off the circles and the "-" between points. Unfortunately, I couldn't find an appropriate plotting function in the matplotlib documentation myself.

推荐答案

有一个stem plot(又名棒棒糖图)也在 matplotlib 中.

There is a stem plot (a.k.a. lollipop plot) in the matplotlib as well.

下面您可以从

如果要调整基线的y位置,可以使用 bottom 参数.

If you want to adjust the y-position of the baseline, you can use the bottom parameter.

(已调整)示例:

import matplotlib.pyplot as plt
import numpy as np

# returns 10 evenly spaced samples from 0.1 to 2*PI
x = np.linspace(0.1, 2 * np.pi, 10)

plt.stem(x, np.cos(x), '-.', bottom=-2)

plt.show()

这篇关于matplotlib中的词干图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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