我正在尝试使用matplotlib绘制以下函数,但是遇到了我从未处理过的问题。
功能:F0*cos((pi*(t-12))/12)
,其中t
是0到86400秒。
我需要每秒计算一次函数,不仅是为了准确性,而且因为此cos表示的函数是以瓦特/ m ^ 2为单位进行度量的。
我正在尝试绘制此函数,但只希望x轴从0到24小时而不是0到86400秒,因此绘制结果不会像这样:
这是我的代码,在此先感谢!
import numpy as np
import matplotlib.pyplot as plt
ax = plt.subplot(111)
F0 = 500.0
t = np.arange(0, 86400, 1)
s = F0*(np.cos((np.pi*(t-12))/12))
line, = plt.plot(t, s, lw=1)
plt.show()
答案 0 :(得分:2)
在计算t
之前,您需要将s
除以3600,然后将s
除以3600,这是因为您在方程式中使用的因子12是小时。如果在计算import numpy as np
import matplotlib.pyplot as plt
ax = plt.subplot(111)
F0 = 500.0
t = np.arange(0, 86400, 1)/3600
s = F0*(np.cos((np.pi*(t-12))/12))
line, = plt.plot(t, s)
之后转换它们,将不会获得所需的绘图。所以你应该使用
s
PS 不要执行以下操作,因为在这里您以秒为单位计算时间来计算t = np.arange(0, 86400, 1)
s = F0*(np.cos((np.pi*(t-12))/12))
line, = plt.plot(t/3600, s)
,然后以小时为单位绘制时间,这会在x轴上产生错误的缩放比例
const Discord = require('discord.js');
const bot = new Discord.Client();
bot.on('error' => console.log);
bot.on('message', message => {
let prefix = '!';
let sender = message.author;
let msg = message.content;
let cont = msg.split(' ');
let args = cont.slice(1);
let cmd = msg.startsWith(prefix) ? cont[0].slice(prefix.length).toUpperCase() : undefined;
// Ping function
// can be: function pingCommand () {...}
let pingCommand = () => {
message.channel.send(`Pong!\nTime: ${bot.ping} ms`);
}
// Main command
if (cmd === 'PING') {
pingCommand();
}
// Calling command in another command
if (cmd === 'TEST') {
message.channel.send('Running a ping test on the bot');
pingCommand();
}
});
bot.login(token);