Time scale on x axis

270 views
Skip to first unread message

Michael Hart

unread,
Aug 23, 2022, 7:31:19 PM8/23/22
to openpyxl-users
Hi, I have searched high and low, but I cannot find out how to set the x axis scale to time of day.
Many examples of date on the x axis, and some of how to do it in Excel, but I couldn't find out now to do it in Openpyxl
I have attached a python file and xlsx output from my attempt to do this, the data is tide heights vs time.
Any help please ?
OpenPyXl_MyChartTest.xlsx
OpenPyXl_MyChartTest.py

Michael Hart

unread,
Aug 24, 2022, 12:36:50 AM8/24/22
to openpyxl-users
I worked out how to do it, I needed to convert the time string to a python datetime using datetime.strptime then to a datetime.time and format the range with the x values in it to "hh:mm" so the seconds aren't shown in the times or the graph.
Works like a charm, code and spreadsheet attached.
OpenPyXl_MyChartTest2.py
OpenPyXl_MyChartTest2.xlsx

Charlie Clark

unread,
Aug 24, 2022, 9:27:36 AM8/24/22
to openpyxl-users

On 24 Aug 2022, at 6:36, Michael Hart wrote:

I worked out how to do it, I needed to convert the time string to a python

datetime using datetime.strptime then to a datetime.time and format the

range with the x values in it to "hh:mm" so the seconds aren't shown in the

times or the graph.

Works like a charm, code and spreadsheet attached.

Glad you got it working though, please, try and avoid using ws["A" + str(…)]" in your code. Use ws.cell() or ws.iter_rows() and your life will be easier! Indexing and slicing are really for convenience only in the shell.

Charlie

--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Sengelsweg 34
Düsseldorf
D- 40489
Tel: +49-203-3925-0390
Mobile: +49-178-782-6226

Michael Hart

unread,
Aug 24, 2022, 8:48:19 PM8/24/22
to openpyx...@googlegroups.com

Thank you Charlie, I will do that,

Michael

--
You received this message because you are subscribed to a topic in the Google Groups "openpyxl-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openpyxl-users/OmqTtXOGvms/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openpyxl-user...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/openpyxl-users/F7516073-1FB4-4D2F-ACE4-79ECC0803DEF%40clark-consulting.eu.
Reply all
Reply to author
Forward
0 new messages