-
Notifications
You must be signed in to change notification settings - Fork 803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve display of date/time tick labels #108
Comments
Working Solution
plt.Ticks(dateTimeX: true); plt.Ticks(dateTimeX: true, dateTimeY: true); Improvements
|
Thanks Scott, I will test this |
Back at my desk, just pulled and synched the 100k+ additions. |
@Padanian your points about the convenience and accuracy of using However, for plotting on a graph we don't need this level accuracy. A big win comes from using plt.Ticks(dateTimeX: true); I added an example to the cookbook: Currently date ticks display surprisingly well considering how simple the code is: it just changes the string labels of the ticks. Usually ticks are just |
Please note that not every double precision number has a correct
conversion to Datetime.
It must be a value between -657435.0 through +2958465.99999999,
therefore it's prone to underflow and overflow which may cause
ArgumentException [1].Finally, MS reports that there is at least one
singularity that can't be properly identified as exact date, e.g. +0.5
and -0.5 both mean noon, december 30th, 1899
Links:
------
[1]
https://docs.microsoft.com/it-it/dotnet/api/system.argumentexception?view=netframework-4.8
|
Unix time may be a better option. With Unix time the numbers are the number of seconds since January 1st, 1970. I don't think this time format has limits. Minutes and hours area much easier in Unix time (multipliers of 60 and 60*60) as opposed to DateTime (where an hour is 1/24) |
God forbid, what if one needs to plot events in the past, like historical or climatological centuries-long data?
|
That person would probably plot year on the horizontal axis. You don't need a time system that supports milliseconds when plotting centuries-long data. I think Unix time is commonly used in internet programming. I run across it a lot in PHP and Python. It seems to be supported by .NET but only int (not double)
EDIT: Rather than supporting double, they have separate functions for millisecond conversion |
This comment has been minimized.
This comment has been minimized.
Hi @FadyDev2, as you can see this topic was actively discussed a few months ago, but hasn't been worked on much since then. If I remember correctly some very fancy date support was added, but the code exploded in complexity (100s of lines of code), then those features got cut out when refactoring required rewriting the axis/tick system. I'll reopen this issue to remind myself to review what it would take to add improved date support to axis labels. |
DateTimeTicks.GetTicks() is now used to generate tick positions and labels when "dateTimeX" or "dateTimeY" is in use. Currently this method is dumb, but it can be improved by adding private methods to this class. This is part of #108
Currently users can turn DateTime display on like this: plt.Ticks(dateTimeX: true); There is now a Currently, the display of DateTime ticks is still very poor. However, this new class is now a single place which can be modified (using only private methods) to provide excellent DateTime tick display. @Padanian contributed some code previously (TickExperimental.cs) which may be useful. |
I ended-up writing the DateTime tick calculator from scratch (DateTimeTicks.cs). It's a lot of lines but I think it's easy to read. Anyone wanting to improve the DateTime tick display can do so by modifying this file (and not worry about breaking anything else). The result looks great! I'll issue a NuGet release containing these updates shortly. |
Dear Scott, |
hey @FadyDev2, I'll fix a last couple things then publish this on NuGet tonight and update this issue when I do. |
@FadyDev2 this is live on NuGet now (ScottPlot 4.0.3) |
Thanks a lot for your quick implementation and replies :) I have another idea that may be of a good use. I hope something like that could be add to ScottPlot. Thanks in advance for your creativity :) |
I like the idea - I’ll look into it! |
after upgrading local DateTime display format #108
It seems the best way to do this is to use the DateTime.ToString() functions: I made everything locale based simply using |
Well done @swharden I wonder if that also could be localized. Thanks and have a nice day. |
You're right! I changed the hard-coded format to use The fix is to change this line to: labels[i] = ticks[i].ToString("MMM yyyy"); |
Fixed in ScottPlot 4.0.9 (live on NuGet) |
DateTimeTicks.GetTicks() is now used to generate tick positions and labels when "dateTimeX" or "dateTimeY" is in use. Currently this method is dumb, but it can be improved by adding private methods to this class. This is part of ScottPlot#108
addresses ScottPlot#108
raised in ScottPlot#108
after upgrading local DateTime display format ScottPlot#108
Now that the tick module has been refactored, simplified (<200 lines), and is working well, the time has come to add support to display tick labels as date and time. This can probably done in just a few lines of new code by intercepting the function which populates
TickCollection.tickLabels
:https://github.com/swharden/ScottPlot/blob/8239f72a94da61aa5c558650ec526ad61732d243/src/ScottPlot/TickCollection.cs#L56-L57
Hopefully we can get this working with as few lines of code as possible, then we can always add complexity later.
A logical next step is to provide smart tick spacing for weeks, days, hours, and minutes (not always multiples of 2 or 5). @Padanian made some excellent progress toward this end, but the code was moved to /dev/code/TickExperimental.cs to be brought out again when date support was added.
The text was updated successfully, but these errors were encountered: