0

I have a dataset with datetimes that sometimes contain differences in seconds.

I have the datetimes (on x-axis) displayed vertically in hopes that the text won't overlap each other, but from the looks of it they're stacked practically on top of each other. I think this is because I have data that differ in seconds and the dates can range through different days, so the x-axis is very tight. Another problem with this is that the datapoints on the graph are also overlapping because the distance between them is so tight.

Here's an example set (already converted using date2num()). It differs in seconds, but spans over several days:

dates = [734949.584699074, 734959.4604050926, 734959.4888773148, 734949.5844791667, 734959.037025463, 734959.0425810185, 734959.0522916666, 734959.4607060185, 734959.4891435185, 734949.5819444444, 734959.0348726852, 734959.0390393519, 734959.0432175926, 734959.0515393518, 734959.4864814815, 734949.5842476852, 734959.0367476852, 734959.038125, 734959.0423032407, 734959.052025463, 734959.4603819444, 734959.4895023148, 734949.5819791667, 734959.0348958333, 734959.0390740741, 734959.0432407408, 734959.0515856481, 734959.4579976852, 734959.487175926]

values =  [39, 68, 27, 57, 22, 33, 70, 19, 60, 53, 52, 33, 87, 63, 78, 34, 26, 42, 24, 97, 20, 1, 32, 60, 61, 48, 30, 48, 17]

dformat = mpl.dates.DateFormatter('%m-%d-%Y %H:%M:%S')
figure = plt.figure()
graph = figure.add_subplot(111)
graph.xaxis.set_major_formatter(dformat)
plt.xticks(rotation='vertical')
figure.subplots_adjust(bottom=.35)
graph.plot_date(dates,values)
graph.set_xticks(dates)
plt.show()

I have two questions:

  • Is there a way to create a spacing on the x-axis so that I can see the text and the datapoints clearly? This would result in a very long horizontal graph, but I will save this to an image file.

  • Relates to first question: to reduce the horizontal length of the graph, is there a way to compress ticks on the x-axis so that areas which have no data will be shortened?

    For example, if we have three dates with values:

     March 22 2013 23:11:04        55
    
     March 22 2013 23:11:10        70
    
     April 1 2013 10:43:56         5
    

    Is it possible to condense the spaces between March 22 23:11:10 and April 1 2013 1-:43:56?

tabx
  • 49
  • 1
  • 6
  • Here is the answer to your second question: http://stackoverflow.com/questions/5656798/python-matplotlib-is-there-a-way-to-make-a-discontinuous-axis – dermen Apr 01 '13 at 17:18
  • What have you tried? You will get better answers if we have some existing code to work from. – tacaswell Apr 01 '13 at 18:11
  • I've updated my question to include an example code. – tabx Apr 01 '13 at 18:31
  • why don't you do this as three separate graphs? – tacaswell Apr 01 '13 at 19:25
  • I'm not sure how I would split this into "three separate graphs". Could you expand on that? At the moment, I'm trying to display all the points onto one graph, kinda like an overview of the system on a timeline. – tabx Apr 01 '13 at 19:49
  • I mean, you can't really do what you want on a linear scale, either your points will be stacked up, or you will have and absurd amount of white space. With out really knowing what you are trying to do, I would suggest either following the link in @dermen 's comment, or just using multiple separate axes. – tacaswell Apr 01 '13 at 21:54
  • as a side note, if you want to make sure someone sees your comment include @_their_name in your comment (hence @tcaswell will ping me). I would have replied earlier, but didn't know you had responded. – tacaswell Apr 01 '13 at 21:55
  • @tcaswell Thanks for the tip. Dermen's link is a great, but the spacing between the xaxis ticks will still be very very small. His link points to the solution for decreasing the empty space. I'm not doing anything fancy with the data at the moment, except provide a somewhat eye-candy timeline of all the points, purely for aesthetics. For example, it would be nice to see point clouds gather on some part of the timeline, but also clearly see the second differences between the data points. [example cloud](http://www.personal.psu.edu/nmc15/blogs/anthspace/acaray_synth_transformed.jpg). – tabx Apr 02 '13 at 20:41
  • @tcaswell You're right about the massive whitespace that will occur, but I think for now this is okay as I'll be saving it to an image file. I'll play with Dermen's link as well, but at the moment the most pressing problem is not having the data points be all squished together because the spacing between the ticks is very very small. Can you think of anything that would help increase this spacing? – tabx Apr 02 '13 at 20:45

1 Answers1

0

You are basically asking for something impossible, you can not both see a range of days and have differences of a few seconds be apparent while keeping the x-axis linear. If you want to try this, you can do something like (doc)

fig.set_size_inches(1000, 2, forward=True)

which will make you figure 1000 inches wide and 2 inches tall, but doing that is rather ungainly.

What I think you should do is apply Dermen's link (Python/Matplotlib - Is there a way to make a discontinuous axis?) with a break anyplace your data has a big break. You will end up with multiple sections that are each a few seconds wide which will give enough space of the tick labels to be readable.

Community
  • 1
  • 1
tacaswell
  • 84,579
  • 22
  • 210
  • 199