- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
通常,您有一组与时间值相关的事件(访问网站、价格信息等),比如说时间戳(尽管日期时间对象就可以了)。如何绘制它们,以便时间轴获得人类可读的、有意义的值,而不仅仅是秒数?
我一直在寻找 gnuplot 和 matplot,但我还没有找到完成此操作的方法。问题是,虽然 matplot 可以每小时设置一次刻度,但最好能够每 N 小时查看一次文本时间信息,而不必对它们进行计数。
我怀疑 gnuplot 太过分了/并不是为此而设计的。有什么建议吗?
最佳答案
FWIW 这是一个使用优秀且文档齐全的 matplotlib 绘制一些值与时间的简单示例:
data.csv: VISIT_TIME TOTAL_VISITS 06:00:00 290 06:30:00 306 07:00:00 364 07:30:00 363 08:00:00 469 08:30:00 436 09:00:00 449 09:30:00 451 10:00:00 524 10:30:00 506 11:00:00 613 11:30:00 585 12:00:00 620 12:30:00 529 13:00:00 588 13:30:00 545
Simple program for illustrative purposes:
import matplotlib.dates as mdates
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import datetime as dt
import sys
def main( datafile ):
np_rec_array = mlab.csv2rec( datafile, delimiter='\t' )
np_rec_array.sort() # in-place sort
# a `figure` is a starting point for MPL visualizations
fig = plt.figure( figsize=(8,6) )
# add a set of `axes` to above `figure`
ax = fig.add_subplot(111)
x = np_rec_array.visit_time
y = np_rec_array.total_visits
# `plot_date` is like `plot` but allows for easier x-axis formatting
ax.plot_date(x, y, 'o-', color='g')
# show time every 30 minutes
ax.xaxis.set_major_locator( mdates.MinuteLocator(interval=30) )
# specify time format
ax.xaxis.set_major_formatter( mdates.DateFormatter("%H:%M") )
# set x-axis label rotation (otherwise they can overlap)
for l in ax.get_xticklabels():
l.set_rotation(60)
plt.title( 'Website Visits' )
plt.show()
if __name__ == '__main__':
if len( sys.argv ) == 1:
sys.stderr.write( 'need a filename, exiting...' )
sys.exit(-1)
main( sys.argv[1] )
输出如下图:
关于python - 如何使用 python 以一种自然的人类可读的方式绘制与时间相关的信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6092561/
有没有一种方法(程序、库)可以大致了解文档是用哪种语言编写的? 我有一堆混合语言的文本文档(~500K),需要导入支持 i18n 的 CMS (Drupal).. 我不需要完美的匹配,只需要一些猜测。
Closed. This question needs details or clarity。它当前不接受答案。
使用 UTF-8 编码。 (Multiple languages in one HTML page)。 跨不同浏览器(包括 iPad 上的 Safari)在单个网页上正确显示多种人类语言的最佳做法是什
我有一个完全可用的代码,它是为 Windows 编写的,是用 Visual Studio 构建的。 我想做的是为该软件添加另一种语言。我的想法是在窗口角落放置两个标志(一个英语和一个德语),并在用户点
我刚刚得到一个脚本,我想对其进行一些更改,我正在寻找某人为我开发一份自由职业,以使我将提供的加载字符串可读以进行编辑。 Lua代码是这样的: ------------------------- ENG
有没有不是简单逐字翻译的语言翻译项目?一个具有先进算法/设计的? 目前主流和流行的翻译软件,例如谷歌翻译,似乎是查找一个词或一组连续的词,然后将其直接翻译成不知何故确定为最佳匹配的内容。但是因为它不是
基于 Twilio 的人类/非人类检测 - 我正在尝试通过如下所示的代码来检测调用是否被人类或机器人接听 HashMap params = new HashMap(); params.put("Fro
这是目前(不确定)我能想到的处理多语言网站的最佳方式,它不涉及 gettext、zend_translate 或任何 php 插件或框架。 我认为它非常简单:我有 3 种语言,我将它们的“内容”写在不
我是一名优秀的程序员,十分优秀!