You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was wondering if there is a way to reformat the data on the X Axis?
I'm able to open audio files and display their waveforms, however I'd like to be able to show the X Axis in a time code, instead of samples.
I've looked at the format-strings for plt.Ticks(numericFormatStringX: "t"), however it's just reformatting values in the millions and trying to get a time, which isn't working.
With 44100 samples a second, you can imagine the numbers don't work well at all...
Something like this maybe, I don't know...
x value = formatstring( x value / samplerate, "d:hh:mm:ss:mmm")
Is there a way to convert these values to time properly? Or can you point me in the right direction?
Please note that the sampling rate is provided in samples per day, not samples per second.
The disadvantage of this solution is that the minimum tick size is 1 second.
Maybe for your task it is enough just to specify the sampling rate, and then 1 count will mean 1 second without converting the XAxis to DateTime format?
I've discovered that while the above suggestions do change the axis, it also seems to change the entire data set when it's plotted, rather than just the time axis. But alas It won't format for me at "hh:mm:ss:mmm" on the X Axis.
After having a brief look through the ~ScottPlot\Config\DateTimeTicks.cs file, it doesn't seem like trivial change to me at this stage.
Wow, I'm absolutely amazed that you'd go to all this trouble. Thanks so much. I've seen the PR details and have not had a chance to try anything as yet. But, I have made a quick screenshot of my work in progress of what I'm working on and trying to do, specifically for context. Please note, it's not finished, and is currently in 'play/design mode'.
I'll review the PR and see if I need to add anything further to it.
Hi @vrdriver, thanks for raising this issue! I like the idea of supporting time codes, as using ScottPlot to work with audio is an excellent use for this graphing library. Your screenshot mock-up really helps me better understand the goal here, thanks for posting it!
I anticipate being able to put some time into this over the weekend, then releasing an updated NuGet package once we get it figured out. @StendProg is making excellent progress in #539, so I anticipate we will figure this out soon!
Thanks Scott, and yes, like you have done with your spectral viewer (which I may incorporate at some stage), I'm also using naudio. I see those two as the perfect combination for this kind of thing.
You may have come across this video series, and while good for the concept, your ScottPlot blew it out of the water for speed. https://www.youtube.com/watch?v=BP2MhB2KQe0
The bug relating to display of negative values (in #549) is still present but we are getting closer!
EDIT: Tick spacing looks bad if the plot is zoomed to include more negative time because negative DateTime values are not valid. A solution is to offset the plot, perhaps by today's date (~2000 years)
varplt=newScottPlot.Plot(800,300);// simulate 10 seconds of audio dataintpointsPerSecond=44100;Randomrand=newRandom(0);double[]ys=DataGen.RandomWalk(rand,pointsPerSecond*10);// for DateTime compatibility, sample rate must be points/daydoublepointsPerDay=24.0*60*60*pointsPerSecond;plt.PlotSignal(ys,sampleRate:pointsPerDay);plt.Ticks(dateTimeX:true,dateTimeFormatStringX:"HH:mm:ss:fff");
@StendProg, I added a format argument to IDateTimeUnit.GetTicksAndLabels(), then modified DateTimeTickUnitBase.GetTicksAndLabels() to use that format string if it is not null. This is probably the best way to do this, but you may want to look at 16740ec to be sure you agree.
I think this is fully solved now. I'll release a NuGet package in an hour or two, and @vrdriver I look forward to hearing how it works in your hands! 👍
I spent some time on this tonight. Obviously not enough just yet as it's not working for me as yet. I was hoping it was going to be a drop in replacement, but I haven't had that happen just yet...
I've deliberately left in the reference preceding code related to naudio of how I'm getting my values so you know where I'm coming from a little more.
I did find that it performed very strangely with adding the samplerate field option and the suggested values. You'll see that in the second part of the video, where it's just basically me scrolling in.
The first section of the video is where it plots fine, but the timecode is still a little wrong, Then after adding the samplerate code, you can see where the wave form almost vanishes to a sliver at .00000000000000001 (you get the picture) seconds.
I did have the times working at one stage, however I discovered that the graph itself wasn't actually wasn't plotting, correctly - or at all. I'll keep playing with it and see how I go. If could be that I've got other settings added.
The upgrade went without too many hitches. This surprisingly appeared
But, I was able to quickly fix that up quickly though.
In all honesty, it's probably something I've done or a setting I've added, so I'll keep trying and see how I go though, but I thought I'd just keep you up to date. I'm excited to get it going. :)
FormsPlot formsPlot1 = Application.OpenForms["Form1"].Controls["formsPlot1"] as FormsPlot;
double pointsPerDay = 24.0 * 60 * 60 * Global.special_sample_rate[0]; // 44100
formsPlot1.plt.Clear();
formsPlot1.plt.AxisBounds(0, samples, -1, 1);
formsPlot1.Configure(lockVerticalAxis: true);
// At the moment, adding samplerate breaks it.
// sampleRate: pointsPerDay,
formsPlot1.plt.PlotSignal(dataX1, color: Color.SkyBlue); // Makes it draw
formsPlot1.plt.PlotSignal(dataX2, color: Color.LightBlue); // Makes it draw
formsPlot1.plt.Style(ScottPlot.Style.Gray1);
formsPlot1.plt.AxisAuto(tightenLayout: true);
formsPlot1.plt.Ticks(displayTicksY: false );
formsPlot1.plt.Frame(left: false, right: false, top: false);
formsPlot1.plt.TightenLayout(padding: 0, render: true);
formsPlot1.Configure(recalculateLayoutOnMouseUp: false);
formsPlot1.plt.Grid(lineStyle: LineStyle.Dot);
formsPlot1.Render();
varplt=newScottPlot.Plot(600,400);// simulate 10 seconds of audio dataintpointsPerSecond=44100;Randomrand=newRandom(0);double[]ys=DataGen.RandomWalk(rand,pointsPerSecond*10);// For DateTime compatibility, sample rate must be points/day.// Also, avoid negative dates by offsetting the plot by today's date.doublesecondsPerDay=24*60*60;doublepointsPerDay=secondsPerDay*pointsPerSecond;doubletoday=DateTime.Today.ToOADate();plt.PlotSignal(ys,sampleRate:pointsPerDay,xOffset:today);plt.Ticks(dateTimeX:true,dateTimeFormatStringX:"HH:mm:ss.fff");
Hi Scott, Yes, I was looking at the cookbook online and in the codebase. I think I'd taken out the "plt.Ticks (dateTimeX: true);" in the video example previously, as it was doing something weird at the time as well. I'd tested it all.
Looking back on it now, I think that my original problem could have been that I was setting up the control on form_load to make it look pretty when the program loaded, which could have easily given it the wrong settings
With all that in mind though, I have some good news. I created a new plot control, and your code tested out and worked fine (no surprises there). So, with that in mind, I proceeded to integrate my dataset in to it.
After a lot of trial and error I've managed to get it to render correctly.
FormsPlot formsPlot2 = Application.OpenForms["Form1"].Controls["formsPlot2"] as FormsPlot;
int pointsPerSecond = 44100; // fixed value for the example
// For DateTime compatibility, sample rate must be points/day.
// Also, avoid negative dates by offsetting the plot by today's date.
double secondsPerDay = 24 * 60 * 60;
double pointsPerDay = secondsPerDay * pointsPerSecond;
double today = DateTime.Today.ToOADate();
formsPlot2.plt.Clear();
formsPlot2.plt.AxisBounds(0, ((double)samples / (double)pointsPerDay), 0, 1);
formsPlot2.Configure(lockVerticalAxis: true);
formsPlot2.plt.PlotSignal(dataX1, sampleRate: pointsPerDay, color: Color.SkyBlue); // Makes it draw
formsPlot2.plt.PlotSignal(dataX2, sampleRate: pointsPerDay, color: Color.LightBlue); // Makes it draw
formsPlot2.plt.Ticks(rulerModeX: true, displayTicksY: false, dateTimeX: true, dateTimeFormatStringX: "HH:mm:ss.fff");
formsPlot2.Render();
The trial and error was not the initial rendering, but getting it to function correctly with my existing code base.
It's worth noting that because of the sampleRate conversion that happens, all of the VLines are now in micro values.
vLine_intro: 0.00137029864662816
I'll just have to do a bit of refactoring to get the values back to the time values, but I don't think this will be too hard in the end.
all of the VLines are now in micro values. vLine_intro = 0.00137029864662816
This is indeed awkward! When .NET converts a DateTime to a double, the number it produces is the number of days since 1900. Since the values are days, a minute and a half will be a very small fraction of a day.
I don't think this will be too hard in the end.
I'm really happy you figured out something that will work for you! Your application is looking fantastic, congratulations!
Let us know if any questions pop up in the future 👍
Scott
Activity
StendProg commentedon Sep 9, 2020
Hi @vrdriver,
You can provide sampleRate to
PlotSingal()and setXAxisto date time by:Please note that the sampling rate is provided in samples per day, not samples per second.
The disadvantage of this solution is that the minimum tick size is 1 second.
Maybe for your task it is enough just to specify the sampling rate, and then 1 count will mean 1 second without converting the
XAxistoDateTimeformat?vrdriver commentedon Sep 10, 2020
I've just tried that, and while it didn't work, I'll keep plugging away. You may have pointed me in the right direction though.
vrdriver commentedon Sep 10, 2020
I've discovered that while the above suggestions do change the axis, it also seems to change the entire data set when it's plotted, rather than just the time axis. But alas It won't format for me at "hh:mm:ss:mmm" on the X Axis.
After having a brief look through the ~ScottPlot\Config\DateTimeTicks.cs file, it doesn't seem like trivial change to me at this stage.
StendProg commentedon Sep 10, 2020
I found a temponary solution for the problem. Do you want to see something like that?

last 4 digit is ms.
This solution temponary, i don't think should be implemented in PR, I just describe it if you familar with source code changes:
dateTimeaxis system.change https://github.com/swharden/ScottPlot/blob/044c2587d990afea5d109d49f8d0432580b57cd5/src/ScottPlot/Config/TickCollection.cs#L59
to
RecalculatePositionsAutomaticNumeric(settings);https://github.com/swharden/ScottPlot/blob/044c2587d990afea5d109d49f8d0432580b57cd5/src/ScottPlot/Config/TickCollection.cs#L365-L366 with
or just hack into and specify format you want after that if/elses
Please note that
msspecified withf.New
DateTime Axissystem is too complex for me. I think only Scott (@swharden ) can change it, when he will have time.StendProg commentedon Sep 10, 2020
PR #539 brings millisecond ticks on
DateTimeAxis.vrdriver commentedon Sep 11, 2020
Wow, I'm absolutely amazed that you'd go to all this trouble. Thanks so much. I've seen the PR details and have not had a chance to try anything as yet. But, I have made a quick screenshot of my work in progress of what I'm working on and trying to do, specifically for context. Please note, it's not finished, and is currently in 'play/design mode'.

I'll review the PR and see if I need to add anything further to it.
swharden commentedon Sep 11, 2020
Hi @vrdriver, thanks for raising this issue! I like the idea of supporting time codes, as using ScottPlot to work with audio is an excellent use for this graphing library. Your screenshot mock-up really helps me better understand the goal here, thanks for posting it!
I anticipate being able to put some time into this over the weekend, then releasing an updated NuGet package once we get it figured out. @StendProg is making excellent progress in #539, so I anticipate we will figure this out soon!
vrdriver commentedon Sep 11, 2020
Thanks Scott, and yes, like you have done with your spectral viewer (which I may incorporate at some stage), I'm also using naudio. I see those two as the perfect combination for this kind of thing.
You may have come across this video series, and while good for the concept, your ScottPlot blew it out of the water for speed.
https://www.youtube.com/watch?v=BP2MhB2KQe0
DateTime ticks now support custom format
example plots using time codes
swharden commentedon Sep 20, 2020
The bug relating to display of negative values (in #549) is still presentbut we are getting closer!EDIT: Tick spacing looks bad if the plot is zoomed to include more negative time because negative DateTime values are not valid. A solution is to offset the plot, perhaps by today's date (~2000 years)
@StendProg, I added a
formatargument toIDateTimeUnit.GetTicksAndLabels(), then modifiedDateTimeTickUnitBase.GetTicksAndLabels()to use that format string if it is not null. This is probably the best way to do this, but you may want to look at 16740ec to be sure you agree.improve timecode examples
[-]Change the format of the X Axis data?[/-][+]Support timecode-style DateTime tick labels[/+]improve DateTime tick density
improve tick rendering
Update changelog.md
swharden commentedon Sep 20, 2020
I think this is fully solved now. I'll release a NuGet package in an hour or two, and @vrdriver I look forward to hearing how it works in your hands! 👍
vrdriver commentedon Sep 21, 2020
Hi @swharden and @StendProg, Thank you both so much for working on this.
I spent some time on this tonight. Obviously not enough just yet as it's not working for me as yet. I was hoping it was going to be a drop in replacement, but I haven't had that happen just yet...
Here's a rather boring video of me attempting to use the program with the new parameters added.
https://youtu.be/CQB2IJ_pdQ8
I've deliberately left in the reference preceding code related to naudio of how I'm getting my values so you know where I'm coming from a little more.
I did find that it performed very strangely with adding the
samplerate fieldoption and the suggested values. You'll see that in the second part of the video, where it's just basically me scrolling in.The first section of the video is where it plots fine, but the timecode is still a little wrong, Then after adding the samplerate code, you can see where the wave form almost vanishes to a sliver at .00000000000000001 (you get the picture) seconds.
I did have the times working at one stage, however I discovered that the graph itself wasn't actually wasn't plotting, correctly - or at all. I'll keep playing with it and see how I go. If could be that I've got other settings added.
The upgrade went without too many hitches. This surprisingly appeared

But, I was able to quickly fix that up quickly though.

In all honesty, it's probably something I've done or a setting I've added, so I'll keep trying and see how I go though, but I thought I'd just keep you up to date. I'm excited to get it going. :)
StendProg commentedon Sep 21, 2020
Hi @vrdriver,
It looks like you forgot to specify
plt.Ticks (dateTimeX: true);Well, do not forget to provide the
sampleRateinPlotSignal.swharden commentedon Sep 21, 2020
@vrdriver you may find this cookbook example helpful
https://swharden.com/scottplot/cookbooks/4.0.40/#customize-axis-time-code-axis
vrdriver commentedon Sep 22, 2020
Hi Scott, Yes, I was looking at the cookbook online and in the codebase. I think I'd taken out the "plt.Ticks (dateTimeX: true);" in the video example previously, as it was doing something weird at the time as well. I'd tested it all.
Looking back on it now, I think that my original problem could have been that I was setting up the control on form_load to make it look pretty when the program loaded, which could have easily given it the wrong settings
With all that in mind though, I have some good news. I created a new plot control, and your code tested out and worked fine (no surprises there). So, with that in mind, I proceeded to integrate my dataset in to it.
After a lot of trial and error I've managed to get it to render correctly.
The trial and error was not the initial rendering, but getting it to function correctly with my existing code base.
It's worth noting that because of the
sampleRateconversion that happens, all of the VLines are now in micro values.vLine_intro: 0.00137029864662816I'll just have to do a bit of refactoring to get the values back to the time values, but I don't think this will be too hard in the end.
And the time is working.

Thanks again.
swharden commentedon Sep 22, 2020
This is indeed awkward! When .NET converts a
DateTimeto adouble, the number it produces is the number of days since 1900. Since the values are days, a minute and a half will be a very small fraction of a day.I'm really happy you figured out something that will work for you! Your application is looking fantastic, congratulations!
Let us know if any questions pop up in the future 👍
Scott