4
votes

I've been searching for a while now to find out how to remove days of the week from a financial plot with no success.

I need the plot to just include the days of the week and completely miss out the weekends such that there is no 2-day gap in the financial chart.

I have the data in CSV format Open/Low/Close/High and it has the weekend data missing, it plots fine but I can't find how to not show the weekends, any help would be really appreciated.

I'd like to see it say M/T/W/T/F/M/T/W/T/F on the X basically rather than M/T/W/T/F/S/S/M etc...

Cheers,

Chris.

5
I don't think people understand the question. It's NOT about how to remove weekends from the data file. There are NO weekend entries in the data file. The problem is that if you set the x axis to time mode, gnuplot reserves a point on the x axis for EACH calendar day. It inserts blank spaces on the x axis for weekends, EVEN IF there are NO entries for those days. I.e. gnuplot treats the x axis as a continuous timeline containing ALL calendar days. The OP asks how NOT to have spaces corresponding to weekends included (shown) on the x axis, as if those days didn't exists in the calendar at all.MrSparkly

5 Answers

1
votes

As far as I know, this cannot be done with gnuplot itself - you need to bring the file into the desired shape before. If you are on Linux, this can be done with something like

awk '{if( index( $1, "S" ) == 0 ) print $0 >> "new.dat"}' old.dat

where old.dat is your original file and new.dat the new file without weekends. I have assumed here that your data file has the weekday as the first entry in each line.

This would work under Windows as well, but you would need to install Gawk for Windows first.

0
votes

The data is not shown in the file, the file is just weekday based and misses the weekends. If you plot the data you get these 2day gaps at the weekend so I want to remove these gaps. It's more really to do with the x axis having weekends in to make it linear.

Here is an example of part of the file:

2006-03-23T16:59 1.7470 1.7324 1.7471 1.7344 0.0000 0.0000 0.0000 0.0000
2006-03-24T16:59 1.7346 1.7308 1.7441 1.7428 0.0000 0.0000 0.0000 0.0000
2006-03-27T17:59 1.7424 1.7415 1.7492 1.7459 0.0000 0.0000 0.0000 0.0000
2006-03-28T17:59 1.7462 1.7422 1.7537 1.7424 0.0000 0.0000 0.0000 0.0000

If you look at the dates, there are gaps in the file. There should be gaps because these days have no data. The graph however should run without gaps and that is what I am trying to achieve.

0
votes

Using some external tool (I would wrote a bash or python script for that, I believe; it should not be difficult), you can insert lines for weekend days (one line for a day) into your data file, like this:

2006-03-26T00:00 NaN NaN NaN NaN NaN NaN NaN NaN

(or you can just append those NaNs for weekends at the end of data file and use unique keyword)

and then plot, let's say, the first data with using 1:($2) with linespoints, not using 1:2 ...

This should work for you.

0
votes

I just came across set xdtics today. I doubt you're still working on this, but maybe that will be helpful for someone else... (see help xdtics)

0
votes

Assuming your data file isn't missing any weekdays, you can treat the date column as a string type. (If you're missing weekdays, your chart will skip over those dates without allocating any space for them, which is easy to miss, so beware.)

I have a date as the first column in my data file in YYYY-MM-DD format. The data I'm plotting is in the second column. Here are the relevant lines of my gnuplot configuration:

set format x '%s'
plot 'file' using 0:2:xtic(substr(strcol(1),6,10))

The set format line tells gnuplot how to print the x labels. The using config uses column 0 (the index) as the x parameter, column 2 (the data) as the y parameter, and provides special instructions for printing labels: only print characters 6–10. (This chops off the year portion, which helps the label fit without overlapping in my case.)

Also see this SO answer. I wouldn't want to replicate this "broken axis" solution for every weekend, but perhaps it could serve to inspire.