Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

How to plot TimeSeries? #37

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

Closed
wangtieqiao opened this issue Sep 5, 2020 · 9 comments
Closed

How to plot TimeSeries? #37

wangtieqiao opened this issue Sep 5, 2020 · 9 comments

Comments

@wangtieqiao
Copy link

Is there any example notebook to show how to plot timeseries data with time in X-axis?

X-axis data could be any of the Datetime classes like LocalDate, LocalDateTime or ZonedDateTime etc

@alshan
Copy link
Collaborator

alshan commented Sep 6, 2020

Try using scale_x_datetime.

At the moment this is the only way to plot time series. The input series can contain millis since Unix epoch. Also accepted Date, Instant and ZonedDateTime from java.time but these values will be converted to millis since Unix epoch.

LocalDate, LocalTime and LocalDateTime are not supported.

When formatting date-time labels Lets-plot assumes UTC time-zone.

@wangtieqiao
Copy link
Author

wangtieqiao commented Sep 6, 2020

Thanks @alshan that works great!

Another question:

  • inside of Jupyter notebook, how to make the chart interactive? (e.g. pan and zoom)
  • How to add backgroud gridline? (I could not find it from any of the examples)
  • And how to add title to a plot?

@alshan
Copy link
Collaborator

alshan commented Sep 6, 2020

Glad it worked for you. Regarding the other questions:

To add a title use the ggtitle function.

The background gridlines are not there yet but you can generate and style a set of horizontal/vertical lines using geom_hline and geom_vline functions.

We don't have the zoom/pan kind of interactivity. The closest thing could be using the xlim or ylim parameters in coord_xxx function (coord_cartesian for example). Perhaps, if ipywidgets are available, a slider can be used to set these values but nobody ever tried this :).

@wangtieqiao
Copy link
Author

Thanks! great work team!
Any plan add those features in?

@alshan
Copy link
Collaborator

alshan commented Sep 7, 2020

Yes for gridlines, panning/zooming not in the nearest future)

@wangtieqiao
Copy link
Author

Thanks again!
a bit sad to know that zoom/pan will not be available soon.... I am a quant researcher / data scientist dealing with timesries everyday, panning/zooming is essential for my work. I see Kotlin starting to take off in analytic area, but could not find any charting library can replace what I used to in Python. Have tried BeakerX, but their wire to Kotlin kernel is broken. Anyway great work team, can not wait to see more features get into the library.

@alshan
Copy link
Collaborator

alshan commented Sep 7, 2020

Thanks for the feedback! You can try the plotly.kt - not quite sure but it might have panning/zooming.

@alshan
Copy link
Collaborator

alshan commented Mar 23, 2021

Is there any example notebook to show how to plot timeseries data with time in X-axis?

X-axis data could be any of the Datetime classes like LocalDate, LocalDateTime or ZonedDateTime etc

There is a new demo in 1.3.0 with time series on X-axis: https://nbviewer.jupyter.org/github/JetBrains/lets-plot-kotlin/blob/master/docs/examples/jupyter-notebooks/formatting_axes_etc.ipynb

@loehnertz
Copy link

@wangtieqiao
I made myself this method that works pretty well for the grid lines:

    fun hlines(range: IntProgression): Feature {
        val horizontalLine: (Int) -> Feature = { yIntercept: Int ->
            geom_hline(
                yintercept = yIntercept,
                alpha = 0.1,
                color = GENERAL_MUTED_COLOR,
                size = 0.02,
            )
        }

        var horizontalLines: Feature = horizontalLine(range.first)
        for (yIntercept: Int in range.first + range.step until range.last step range.step) {
            horizontalLines += horizontalLine(yIntercept)
        }

        return horizontalLines
    }

It can be used like this:

ggplot(dataFrame) + hlines(-110 until 110 step 5)

Cheers 😊

@JetBrains JetBrains locked and limited conversation to collaborators Sep 28, 2021
@alshan alshan closed this as completed Sep 28, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants