Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7670371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:48:27+00:00 2026-05-31T15:48:27+00:00

I tried to plot chart with datetime x axis: here is example of the

  • 0

I tried to plot chart with datetime x axis:
here is example of the code:

    #!/usr/bin/python2.7 -tt
    # coding: utf-8
    import Gnuplot
    from datetime import datetime
    out_file = 'test.png'
    out_file_str = 'set out "'+out_file+'"'

    #example of chart with options and data
    data = (('10-02-2012 18:00:36', '33.547'), ('10-02-2012 18:01:06', '23.962'), ('10-02-2012 18:04:06', '18.071'), ('10-02-2012 18:35:36', '13.513'), ('10-02-2012 18:47:06', '23.869'), ('10-02-2012 18:51:06', '13.988'), ('10-02-2012 18:56:06', '5.869'), ('10-02-2012 18:56:36', '3.811'), ('10-02-2012 18:59:36', '4.01'))
    ytics = 10
    start_range = '"10-02-2012 18:00:00"'
    end_range = '"10-02-2012 19:00:00"'
    xrange = ( start_range, end_range)
    yrange = ( 0, 50 )

    chart = Gnuplot.Gnuplot()
    set_term = 'set terminal png truecolor size 780,464'
    chart(set_term)
    chart(out_file_str)
    chart('set xdata time')
    set_timefmt = 'set timefmt "%d-%m-%Y %H:%M:%S"'
    chart(set_timefmt)
    set_xformat = 'set format x "%H:%M\\n%d.%m"'
    chart(set_xformat)
    set_yformat = 'set format y "%.0f"'
    chart(set_yformat)
    set_yticformat = 'set ytics format "%.0f"'
    chart(set_yticformat)
    chart('set ytics out nomirror')
    chart('set grid xtics ytics mxtics mytics')
    chart('set xtics axis out scale 1.0,0.1 nomirror')
    chart('set key out horiz')
    chart('set key center')
    chart('set key bmargin')
    set_ytics = 'set ytics ' + str(ytics)
    chart(set_ytics)
    y_range = (0, 100)
    chart.set_range('yrange',y_range)
    chart.set_range('xrange', xrange)

    data1 = []
    for val in data:
      ctime = datetime.strptime(val[0], '%d-%m-%Y %H:%M:%S')
      cur_str = (ctime, val[1])
      data1.append(cur_str)
    for d in data1:
      chart.plot(d[0],d[1])

and this code returns error:

    Fatal: array dimensions not equal!
    Traceback (most recent call last):
      File "./test-gnuplot2.py", line 49, in <module>
        chart.plot(d[0],d[1])
      File "/usr/lib/python2.7/site-packages/Gnuplot/_Gnuplot.py", line 284, in plot
        self._add_to_queue(items)
      File "/usr/lib/python2.7/site-packages/Gnuplot/_Gnuplot.py", line 254, in _add_to_queue
        self.itemlist.append(PlotItems.Data(item))
      File "/usr/lib/python2.7/site-packages/Gnuplot/PlotItems.py", line 554, in Data
        if len(data.shape) == 1:
    AttributeError: 'NoneType' object has no attribute 'shape'

i don’t know how can i plot chart with datetime. it tried to represent datetime as a string, but it didn’t help.
what am i doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:48:28+00:00Added an answer on May 31, 2026 at 3:48 pm

    I tried gnuplot-py a while back, but it had some limitations that were deal-breakers for me. Because of that, I decided to write my own gnuplot wrapper using python. It can be found at:

    http://sourceforge.net/projects/pygnuplot/

    I think it is pretty good. Here’s basic script to plot your graph:

    #!/usr/bin/python2.7 -tt
    # coding: utf-8
    import pyGnuplot
    from datetime import datetime
    out_file = 'test.png'
    out_file_str = 'set out "'+out_file+'"'
    
    #example of chart with options and data
    data = (('10-02-2012 18:00:36', '33.547'),
            ('10-02-2012 18:01:06', '23.962'),
            ('10-02-2012 18:04:06', '18.071'),
            ('10-02-2012 18:35:36', '13.513'),
            ('10-02-2012 18:47:06', '23.869'),
            ('10-02-2012 18:51:06', '13.988'),
            ('10-02-2012 18:56:06', '5.869'),
            ('10-02-2012 18:56:36', '3.811'),
            ('10-02-2012 18:59:36', '4.01'))
    
    ytics = 10
    
    #When str(datatime.datatime), the format is %Y-%m-%d %H:%M:%S, so that
    # is the format pyGnuplot uses by default -- Of course the format you use
    # to create datetime objects is up to you.
    start_range = '"2012-02-10 18:00:00"'
    end_range = '"2012-02-10 19:00:00"'
    xrange = ( start_range, end_range)
    # yrange = ( 0, 50 )
    
    tvals,yvals=zip(*data)
    tvals=[datetime.strptime(i, '%d-%m-%Y %H:%M:%S') for i in tvals]
    print str(tvals[0])
    print tvals
    print yvals
    g = pyGnuplot.gnuplot(debug=1)
    g('set xdata time')
    g('set timefmt "%Y-%d-%m %H:%M:%S"')  #Default datatime output format.
    set_xformat = 'set format x "%H:%M\\n%d.%m"'
    g(set_xformat)
    set_yformat = 'set format y "%.0f"'
    g(set_yformat)
    set_yticformat = 'set ytics format "%.0f"'
    g(set_yticformat)
    g('set ytics out nomirror')
    g('set grid xtics ytics mxtics mytics')
    g('set xtics axis out scale 1.0,0.1 nomirror')
    g('set key out horiz')
    g('set key center')
    g('set key bmargin')
    set_ytics = 'set ytics ' + str(ytics)
    g(set_ytics)
    y_range = (0, 100)
    plt=g.plot(yvals,xvals=tvals,u="1:3")
    plt.xrange(xrange)
    plt.yrange(y_range)
    
    g.show(plt)  #Show the plot in the gnuplot default terminal
    g.hardcopy(plt,file='myfile.png',size='780,464',truecolor=True) #Make a hardcopy
    print g.readlines()  #Get any script error messages from gnuplot
    

    pyGnuplot could probably use some better documentation which is on my TODO list, but I haven’t had a ton of time to do it.

    Also, I have only used pyGnuplot on Linux and Mac, so how well it works on other platforms is currently unknown.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried going through all the examples in core plot, esp dateplot example,
Tried following the instructions here: How to use Google app engine with my own
How would a person dput() an S4 object? I tried this require(sp) require(splancs) plot(0,
Trying to plot a spectrum, ie, velocity versus intensity, with lower x axis =
I've tried a number of things but I can't get my plot to create
I'm trying to attach a legend to a plot in R. I tried the
For example if I have the following code in MATLAB x = 0:0.1:2*pi; y
I'm looking for a way to plot a bar chart containing two different series,
I tried to plot data useage per day using jqPlot along with its DateAxisRenderer
I'm finalizing a new chart that uses a Category Axis as my horizontal, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.