zsh2270365028的个人博客分享 http://blog.sciencenet.cn/u/zsh2270365028

博文

[转载]python Step Demo

已有 543 次阅读 2022-1-28 15:23 |个人分类:Python|系统分类:科研笔记|文章来源:转载

refer to: https://matplotlib.org/stable/gallery/lines_bars_and_markers/step_demo.html#sphx-glr-gallery-lines-bars-and-markers-step-demo-py

Step Demo

This example demonstrates the use of pyplot.step for piece-wise constant curves. In particular, it illustrates the effect of the parameter whereon the step position.

Note

For the common case that you know the edge positions, use pyplot.stairsinstead.

The circular markers created with pyplot.plot show the actual data positions so that it's easier to see the effect of where.

import numpy as npimport matplotlib.pyplot as pltx = np.arange(14)y = np.sin(x / 2)plt.step(x, y + 2, label='pre (default)')plt.plot(x, y + 2, 'o--', color='grey', alpha=0.3)plt.step(x, y + 1, where='mid', label='mid')plt.plot(x, y + 1, 'o--', color='grey', alpha=0.3)plt.step(x, y, where='post', label='post')plt.plot(x, y, 'o--', color='grey', alpha=0.3)plt.grid(axis='x', color='0.95')plt.legend(title='Parameter where:')plt.title('plt.step(where=...)')plt.show()

plt.step(where=...)

The same behavior can be achieved by using the drawstyle parameter ofpyplot.plot.

plt.plot(x, y + 2, drawstyle='steps', label='steps (=steps-pre)')plt.plot(x, y + 2, 'o--', color='grey', alpha=0.3)plt.plot(x, y + 1, drawstyle='steps-mid', label='steps-mid')plt.plot(x, y + 1, 'o--', color='grey', alpha=0.3)plt.plot(x, y, drawstyle='steps-post', label='steps-post')plt.plot(x, y, 'o--', color='grey', alpha=0.3)plt.grid(axis='x', color='0.95')plt.legend(title='Parameter drawstyle:')plt.title('plt.plot(drawstyle=...)')plt.show()

plt.plot(drawstyle=...)

References

The use of the following functions, methods, classes and modules is shown in this example:




https://blog.sciencenet.cn/blog-587102-1323101.html

上一篇:[转载]python Fill Between and Alpha
下一篇:arXiv-2022.2.5

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2022-5-23 20:04

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部