本文整理汇总了Python中matplotlib.dates.datestr2num方法的典型用法代码示例。如果您正苦于以下问题:Python dates.datestr2num方法的具体用法?Python dates.datestr2num怎么用?Python dates.datestr2num使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.dates
的用法示例。
在下文中一共展示了dates.datestr2num方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_autofmt_xdate
# 需要导入模块: from matplotlib import dates [as 别名]
# 或者: from matplotlib.dates import datestr2num [as 别名]
def test_autofmt_xdate(which):
date = ['3 Jan 2013', '4 Jan 2013', '5 Jan 2013', '6 Jan 2013',
'7 Jan 2013', '8 Jan 2013', '9 Jan 2013', '10 Jan 2013',
'11 Jan 2013', '12 Jan 2013', '13 Jan 2013', '14 Jan 2013']
time = ['16:44:00', '16:45:00', '16:46:00', '16:47:00', '16:48:00',
'16:49:00', '16:51:00', '16:52:00', '16:53:00', '16:55:00',
'16:56:00', '16:57:00']
angle = 60
minors = [1, 2, 3, 4, 5, 6, 7]
x = mdates.datestr2num(date)
y = mdates.datestr2num(time)
fig, ax = plt.subplots()
ax.plot(x, y)
ax.yaxis_date()
ax.xaxis_date()
ax.xaxis.set_minor_locator(AutoMinorLocator(2))
ax.xaxis.set_minor_formatter(FixedFormatter(minors))
fig.autofmt_xdate(0.2, angle, 'right', which)
if which in ('both', 'major', None):
for label in fig.axes[0].get_xticklabels(False, 'major'):
assert int(label.get_rotation()) == angle
if which in ('both', 'minor'):
for label in fig.axes[0].get_xticklabels(True, 'minor'):
assert int(label.get_rotation()) == angle
示例2: process_log
# 需要导入模块: from matplotlib import dates [as 别名]
# 或者: from matplotlib.dates import datestr2num [as 别名]
def process_log(log: dict, mode: str):
if len(log) == 0:
raise Exception("Empty log")
set_size = int(log[0]["meta"]["sources_size"])
timestamp = datestr2num(log[0]["meta"]["run_finish_time"])
# Extract filtered list of affected hosts and ranks
carnage = []
for log_data in log[0]["data"]:
if mode == "symantec":
# Old way of counting stopped working once NSS changes removed short error message
# if "short_error_message" in l["response"]["result"]["info"]:
# sm = l["response"]["result"]["info"]["short_error_message"]
# if sm == "SEC_ERROR_UNKNOWN_ISSUER" or sm == "MOZILLA_PKIX_ERROR_ADDITIONAL_POLICY_CONSTRAINT_FAILED":
# errors += 1
# New way of counting is solely filtering by ssl status code
status = log_data["response"]["result"]["info"]["status"]
if status == 2153398259 or status == 2153390067:
carnage.append((int(log_data["rank"]), log_data["host"]))
elif mode == "tlsdeprecation":
status = log_data["response"]["result"]["info"]["short_error_message"]
if status == "SSL_ERROR_UNSUPPORTED_VERSION":
carnage.append((int(log_data["rank"]), log_data["host"]))
else:
raise Exception("Unknown log processing mode: %s" % mode)
carnage = list(sorted(carnage))
# Count numbers for each subset
counts = {}
for key in (100, 1000, 10000, 100000, 1000000):
counts[str(key)] = 0
for rank, _ in carnage:
for key in (100, 1000, 10000, 100000, 1000000):
if rank <= key:
counts[str(key)] += 1
return timestamp, set_size, carnage, counts
示例3: process_logs
# 需要导入模块: from matplotlib import dates [as 别名]
# 或者: from matplotlib.dates import datestr2num [as 别名]
def process_logs(self) -> dict:
# with open("/home/ubuntu/http/broken-%s.csv" % key, "w") as f:
# f.writelines(["%d,%s\n" % x for x in sorted(carnage)])
data = {}
p = Pool()
work_list = list_logs(self.tlscanary_binary, tag=self.log_tag)
results = p.imap_unordered(self.process_log, work_list)
# Add static data compiled by matt
data["1000000"] = {
"timestamps": [
datestr2num("2018-05-22"),
datestr2num("2018-06-26"),
datestr2num("2018-07-17"),
datestr2num("2018-08-15")
],
"values": [
# original set_size was 496833 hosts
100.0 * 35066 / 1000000,
100.0 * 27102 / 1000000,
100.0 * 23197 / 1000000,
100.0 * 17833 / 1000000
]
}
for timestamp, _, counts in sorted(results):
for tier in counts.keys():
# if tier == "100000":
# continue
value = 100.0 * counts[tier] / int(tier)
if tier not in data:
data[tier] = {"timestamps": [timestamp], "values": [value]}
else:
data[tier]["timestamps"].append(timestamp)
data[tier]["values"].append(value)
return data