Python matplotlib.dates.datestr2num() Examples
The following are 5
code examples of matplotlib.dates.datestr2num().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib.dates
, or try the search function
.
Example #1
Source File: test_figure.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #2
Source File: main.py From tls-canary with Mozilla Public License 2.0 | 5 votes |
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
Example #3
Source File: main.py From tls-canary with Mozilla Public License 2.0 | 5 votes |
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
Example #4
Source File: test_figure.py From coffeegrindsize with MIT License | 5 votes |
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
Example #5
Source File: test_figure.py From twitter-stock-recommendation with MIT License | 5 votes |
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