Python模拟脉冲星伪信号频率实例代码
作者:Nicolas P. Rougier 时间:2023-02-12 06:01:08
脉冲星假信号频率的相对路径论证。
首先看一下演示结果:
实例代码:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
# Fixing random state for reproducibility
np.random.seed(19680801)
# Create new Figure with black background
fig = plt.figure(figsize=(8, 8), facecolor='black')
# Add a subplot with no frame
ax = plt.subplot(111, frameon=False)
# Generate random data
data = np.random.uniform(0, 1, (64, 75))
X = np.linspace(-1, 1, data.shape[-1])
G = 1.5 * np.exp(-4 * X ** 2)
# Generate line plots
lines = []
for i in range(len(data)):
# Small reduction of the X extents to get a cheap perspective effect
xscale = 1 - i / 200.
# Same for linewidth (thicker strokes on bottom)
lw = 1.5 - i / 100.0
line, = ax.plot(xscale * X, i + G * data[i], color="w", lw=lw)
lines.append(line)
# Set y limit (or first line is cropped because of thickness)
ax.set_ylim(-1, 70)
# No ticks
ax.set_xticks([])
ax.set_yticks([])
# 2 part titles to get different font weights
ax.text(0.5, 1.0, "MATPLOTLIB ", transform=ax.transAxes,
ha="right", va="bottom", color="w",
family="sans-serif", fontweight="light", fontsize=16)
ax.text(0.5, 1.0, "UNCHAINED", transform=ax.transAxes,
ha="left", va="bottom", color="w",
family="sans-serif", fontweight="bold", fontsize=16)
def update(*args):
# Shift all data to the right
data[:, 1:] = data[:, :-1]
# Fill-in new values
data[:, 0] = np.random.uniform(0, 1, len(data))
# Update data
for i in range(len(data)):
lines[i].set_ydata(i + G * data[i])
# Return modified artists
return lines
# Construct the animation, using the update function as the animation
# director.
anim = animation.FuncAnimation(fig, update, interval=10)
plt.show()
脚本运行时间:(0分0.065秒)
来源:https://matplotlib.org/index.html
标签:python,matplotlib,实例
0
投稿
猜你喜欢
CSS控制鼠标样式变换方法
2007-11-17 07:58:00
python计算牛顿迭代多项式实例分析
2022-10-27 05:32:37
Python中在for循环中嵌套使用if和else语句的技巧
2022-10-08 17:44:50
解决python selenium3启动不了firefox的问题
2022-12-02 11:36:34
页面表达常用方式
2010-05-27 12:42:00
在Recordset对象中查询记录的方法
2008-11-20 16:51:00
Django城市信息查询功能的实现步骤
2023-09-01 21:28:48
Python使用三种方法实现PCA算法
2022-06-26 13:32:49
django form和field具体方法和属性说明
2023-07-24 11:22:45
python如何写出表白程序
2023-12-19 17:10:56
Python集合之set和frozenset的使用详解
2021-06-26 22:41:20
基于keras 模型、结构、权重保存的实现
2022-12-20 06:31:22
python面向对象 反射原理解析
2021-05-14 08:56:32
关于python pycharm中输出的内容不全的解决办法
2023-09-23 16:45:26
Python实现的逻辑回归算法示例【附测试csv文件下载】
2023-12-09 21:08:33
Python unittest模块用法实例分析
2023-03-28 17:36:06
InnoDb 体系架构和特性详解 (Innodb存储引擎读书笔记总结)
2024-01-21 14:21:03
python小技巧之批量抓取美女图片
2022-09-16 17:25:58
Appium+Python实现简单的自动化登录测试的实现
2021-09-13 05:49:14
django中的数据库迁移的实现
2024-01-18 07:35:00