numpy,matplotlib模拟波的调制



# -*- coding: utf-8 -*-
"""
Created on Thu Mar 22 20:31:33 2018

@author: 17061167
#波的采样,波的调制
#乘法器
"""


import matplotlib.pyplot as plt  
import numpy as np

plt.figure(figsize=(8,8),dpi=80) 
x=np.arange(-np.pi,np.pi,0.001)
y=np.sin(x)
#x1=np.arange(-10,10,0.1)
y1=(np.sin(10*np.pi*x))*y
plt.plot(x,y,color='b',linewidth=5)
plt.plot(x,y1,color='r')
plt.show()

傅里叶公式

#
#coding:utf-8

import time
import numpy as np
import matplotlib.pyplot as plt

def cos_n(x,n=1):
    return (2/(n*np.pi))*np.cos(0.5*n*np.pi*x)*np.sin(0.5*n*np.pi)

plt.figure(figsize=(8,8),dpi=80)
x = np.linspace(0, 5* np.pi, 300) #创建一个包含30个点的余弦波信号
#wave = np.cos(x)

wave=0
for i in range(1,15):
    #wave=np.cos(i*x)+wave
    wave=cos_n(x,n=i)+wave
    #plt.hold(True)
    #plt.plot(x,wave)
    #plt.show()
    #time.sleep(2)

plt.legend(loc='upper left')
plt.grid()
plt.plot(x,wave,label="f")
transformed = np.fft.fft(wave)  #使用fft函数对余弦波信号进行傅里叶变换。
#print np.all(np.abs(np.fft.ifft(transformed) - wave) < 10 ** -9)  #对变换后的结果应用ifft函数,应该可以近似地还原初始信号。
#plt.plot(x,transformed,label="FFT")  #使用Matplotlib绘制变换后的信号。
plt.show()



发布了22 篇原创文章 · 获赞 1 · 访问量 2062
展开阅读全文

python用matplotlib画K线

11-18

import matplotlib.pyplot as plt import matplotlib.finance as mpf with open('SH#600004.txt') as obj: text=obj.readlines() baseinfo=text[0] dayinfo=text[2:-1] date_list =[dayinfo[i].split(',')[0] for i in range(len(dayinfo))] open_list =[dayinfo[i].split(',')[1] for i in range(len(dayinfo))] high_list =[dayinfo[i].split(',')[2] for i in range(len(dayinfo))] low_list =[dayinfo[i].split(',')[3] for i in range(len(dayinfo))] close_list=[dayinfo[i].split(',')[4] for i in range(len(dayinfo))] quotes=zip(date_list,open_list,high_list,low_list,close_list) #N=100 #open_list[:N],high_list[:N],low_list[:N],close_list[:N] fig,ax=plt.subplots() mpf.candlestick_ohlc(ax,quotes,width=0.6,colorup='r',colordown='green') plt.title(baseinfo) plt.xlabel(date_list) plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签 plt.rcParams['axes.unicode_minus']=False #用来正常显示负号 plt.show() **#以下是报错信息 C:\ProgramData\Anaconda3\python.exe G:/python/test/test.py C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\cbook\deprecation.py:106: MatplotlibDeprecationWarning: The finance module has been deprecated in mpl 2.0 and will be removed in mpl 2.2. Please use the module mpl_finance instead. warnings.warn(message, mplDeprecation, stacklevel=1) Traceback (most recent call last): File "G:/python/test/test.py", line 18, in <module> mpf.candlestick_ohlc(ax,quotes,width=0.6,colorup='r',colordown='green') File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\finance.py", line 737, in candlestick_ohlc alpha=alpha, ochl=False) File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\finance.py", line 794, in _candlestick height = open - close TypeError: unsupported operand type(s) for -: 'str' and 'str'** 我搜了下知道日期格式转换需要用到date2num这个函数 我的文本里面日期格式是XXXX/XX/XX的形式 请问quotes一项里日期需求的格式是什么? 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 书香水墨 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览