Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #109372

Matplotlib X-axis dates

Path csiph.com!news.mixmin.net!news.unit0.net!fu-berlin.de!uni-berlin.de!not-for-mail
From Joaquin Alzola <Joaquin.Alzola@lebara.com>
Newsgroups comp.lang.python
Subject Matplotlib X-axis dates
Date Thu, 2 Jun 2016 15:45:22 +0000
Lines 86
Message-ID <mailman.99.1464883218.1839.python-list@python.org> (permalink)
References <HE1PR07MB13560091396C4A9B39B57C6FF0580@HE1PR07MB1356.eurprd07.prod.outlook.com>
Mime-Version 1.0
Content-Type text/plain; charset="us-ascii"
Content-Transfer-Encoding quoted-printable
X-Trace news.uni-berlin.de vX0paEx06+ymXJnsQsDlJwntkZpr44iMnIadKVX1q9gQ==
Return-Path <Joaquin.Alzola@lebara.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.056
X-Spam-Evidence '*H*': 0.89; '*S*': 0.00; 'skip:[ 20': 0.03; 'skip:% 20': 0.07; 'skip:# 60': 0.09; 'output': 0.13; 'skip:# 20': 0.13; 'skip:p 40': 0.15; 'privilege.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'result:': 0.16; 'subject:dates': 0.16; 'to:name:python-list@python.org': 0.20; 'skip:% 10': 0.22; 'select': 0.23; 'entries': 0.27; '&quot;': 0.29; 'code:': 0.29; 'shift': 0.33; 'skip:d 20': 0.34; 'skip:c 30': 0.35; 'skip:p 30': 0.35; 'but': 0.36; 'should': 0.36; 'url:org': 0.36; '(and': 0.36; 'to:addr:python-list': 0.36; 'received:10': 0.37; 'url:rec- html40': 0.37; 'charset:us-ascii': 0.37; 'guys': 0.38; 'skip:p 20': 0.38; 'data': 0.39; 'does': 0.39; 'subject:-': 0.39; 'to:addr:python.org': 0.40; 'url:schemas': 0.40; 'url:office': 0.40; 'show': 0.62; 'other.': 0.64; 'skip:a 40': 0.64; 'contact': 0.66; 'day': 0.67; 'subject': 0.70; 'disclose': 0.71; 'country': 0.74; '&agrave;': 0.91; 'url:image': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=lebara.onmicrosoft.com; s=selector1-lebara-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=UIRxjYwULxGuK23RapPjGHPROul6Wmml+XFqIcYZcFY=; b=Z9mObA1z4qU3lezDB6RdjBzSlN2F0xj9tqyMbalBtG8fAhZF6VxwItSWPBaNLH+3qHuN7K/46dD8vrkAIULoC9ZHRv6K1wf0KjjqA64tDd7JszOw5MxeB78Nu7j05hoR6TR4UJ15D4kohrKfEI8a19DCA+d3Hhu0cqj5mI5ZBjo=
Thread-Topic Matplotlib X-axis dates
Thread-Index AdG85NSCA9DGn4W0RxG/6R5Vq/9DSg==
Accept-Language en-GB, en-US
Content-Language en-US
X-MS-Has-Attach
X-MS-TNEF-Correlator
authentication-results python.org; dkim=none (message not signed) header.d=none;python.org; dmarc=none action=none header.from=lebara.com;
x-originating-ip [165.225.80.106]
x-ms-office365-filtering-correlation-id 2c07eaca-14f2-41e5-b569-08d38afce841
x-microsoft-exchange-diagnostics 1; HE1PR07MB1355; 5:f3clMHhdXN4kAYCqWc45bGUGTYjlyGchppZuLt0ExvAArnjkiSwatOON4Z3yK8d8sJdS5w0GW1HiUspTJjKrgN9F14njafggDZJXTXq0+7ECI35Ws/PkPS/oeGnFXReLLynFfBSqQncRiJiQ7GgY5w==; 24:SFGhwc1DmQk4aEz/8LohFDvmSFzT9i+KMjBvyEtXO0sgRiPLBFcrVSxjqOw1fpCsve58neKoHTIv2R7Rjg+GoRCWmyUeHi8rgHqONlHYmTY=; 7:a5t/jowQUS2x3G7ahdpOczurRqob7A8e8UWLCaqlZQ2rvpCZW3phYI/jecqMoC3DNUZQ0ebDcsNvuJbzgkkry9Zdr8HM9XslUsx6NQvpSRv6bV7edRB+71JJ9G/HkiNP7xk1MDotvRICLybUc5iMrpB3p9XjrlHSqgMweHh9z4SwvvdC+j7gEP4uXG8bf7xR
x-microsoft-antispam UriScan:;BCL:0;PCL:0;RULEID:;SRVR:HE1PR07MB1355;
x-microsoft-antispam-prvs <HE1PR07MB1355F45A6E9850CB49DE10C4F0580@HE1PR07MB1355.eurprd07.prod.outlook.com>
x-exchange-antispam-report-test UriScan:(21748063052155);
x-exchange-antispam-report-cfa-test BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001); SRVR:HE1PR07MB1355; BCL:0; PCL:0; RULEID:; SRVR:HE1PR07MB1355;
x-forefront-prvs 0961DF5286
x-forefront-antispam-report SFV:NSPM; SFS:(10019020)(377424004)(5003600100002)(66066001)(122556002)(10400500002)(3280700002)(3846002)(229853001)(102836003)(6116002)(790700001)(2351001)(189998001)(586003)(8676002)(76576001)(92566002)(15975445007)(77096005)(19300405004)(2906002)(2900100001)(5002640100001)(5640700001)(5630700001)(81166006)(110136002)(19617315012)(107886002)(19625215002)(19580395003)(54356999)(50986999)(3660700001)(3480700004)(33656002)(450100001)(86362001)(15395725005)(16236675004)(8936002)(2501003)(74316001)(87936001)(11100500001)(5004730100002)(9686002)(5008740100001)(48910200003); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1PR07MB1355; H:HE1PR07MB1356.eurprd07.prod.outlook.com; FPR:; SPF:None; MLV:ovrnspm; PTR:InfoNoRecords; LANG:en;
spamdiagnosticoutput 1:23
spamdiagnosticmetadata NSPM
X-OriginatorOrg lebara.com
X-MS-Exchange-CrossTenant-originalarrivaltime 02 Jun 2016 15:45:22.1602 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader Hosted
X-MS-Exchange-CrossTenant-id d7093539-83cd-4991-b1b3-aacef74cf097
X-MS-Exchange-Transport-CrossTenantHeadersStamped HE1PR07MB1355
X-Content-Filtered-By Mailman/MimeDel 2.1.22
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <HE1PR07MB13560091396C4A9B39B57C6FF0580@HE1PR07MB1356.eurprd07.prod.outlook.com>
Xref csiph.com comp.lang.python:109372

Show key headers only | View raw


Hi Guys

Have been all day looking for a solution on the x-axis and the time plot.

The output that I get is this with all the dates shift to the right overlapping each other. http://postimg.org/image/fs4tx83or/

I want the x-axis to start at 0 and to finish after the 3 entries on the DB.

X Axis should show (and it does but shift one over each other to the right):
2016-06-02 11:15:00
2016-06-02 11:20:00
2016-06-02 11:25:00

Data on the Cassandra DB:
cqlsh:lebara_diameter_codes> select * from nl_lebara_diameter_codes;

country | service | date                            | errorcode2001 | errorcode3056 | errorcode4010 | errorcode4012 | errorcode4998 | errorcode4999 | errorcode5012
---------+---------+---------------------------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------
      NL |    gprs | 2016-06-02 11:15:00.000000+0000 |          3061 |             0 |             1 |             0 |             0 |            50 |           741
      NL |    gprs | 2016-06-02 11:20:00.000000+0000 |          3204 |             0 |             9 |             0 |             0 |            56 |           725
      NL |    gprs | 2016-06-02 11:25:00.000000+0000 |          3044 |             0 |             8 |             0 |             0 |            64 |           722


Code:
sql = country_sql("NL",ago.strftime('%Y-%m-%d %H:%M:%S'),"gprs")
result = sql.sql_statement_range()
for i in result:
        country = i.country
        service = i.service
        x_list.append(i.date)
        code_2001.append(i.errorcode2001)
        code_4012.append(i.errorcode4012)
        code_4998.append(i.errorcode4998)
        code_4999.append(i.errorcode4999)
        code_5012.append(i.errorcode5012)
        code_3056.append(i.errorcode3056)
        code_4010.append(i.errorcode4010)

print(x_list)   --> Output is [datetime.datetime(2016, 6, 2, 11, 15), datetime.datetime(2016, 6, 2, 11, 20), datetime.datetime(2016, 6, 2, 11, 25)]
#date_nump=date2num([i for i in x_list])
date_nump=date2num(x_list)
print(date_nump) --> output is [ 736117.46875     736117.47222222  736117.47569444]
fig = plt.figure(figsize=(12,6))
ax = fig.add_subplot(111)
ax.set_title(country.upper() + " " + service,fontsize=16, fontweight='bold')
plt.plot(np.array(code_2001),label="2001")
plt.plot(np.array(code_3056),label="3056")
plt.plot(np.array(code_4010),label="4010")
plt.plot(np.array(code_4012),label="4012")
plt.plot(np.array(code_4998),label="4998")
plt.plot(np.array(code_4999),label="4999")
plt.plot(np.array(code_5012),label="5012")
lgd = plt.legend(loc='center left', bbox_to_anchor=(1, 0.5))
ax.set_xscale('linear')
ax.set_xticks(date_nump)
ax.set_xticklabels(num2date(date_nump))
#ax.xaxis.set_major_locator(HourLocator(byhour=range(0,24,2)))
ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d %H:%M:%S'))
#ax.xaxis.set_minor_locator(MinuteLocator())
ax.grid(True,linestyle='-',color='0.75')
plt.gcf().autofmt_xdate(bottom=0.2, rotation=30, ha='right')
plt.ylabel('Total Amount',fontsize=12, fontweight='bold')
plt.xlabel('Date/Time',fontsize=12, fontweight='bold')
plt.gca().set_ylim(bottom=0)
plt.savefig('testplot.png',bbox_extra_artists=(lgd,), bbox_inches='tight')
plt.show()
This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Matplotlib X-axis dates Joaquin Alzola <Joaquin.Alzola@lebara.com> - 2016-06-02 15:45 +0000

csiph-web