cpplot icon indicating copy to clipboard operation
cpplot copied to clipboard

Timeseries Support

Open tdtooke opened this issue 4 years ago • 2 comments

First: I love this. I have been searching for a way to have plotly on C++. I'm plotting graphs of temperature against time. Currently I'm doing this in QT with QTCharts and graphing that way you can define an axis as time. Right now my time object, pre-cpplot is a QLineSeries where the QDateTime is converted with toMSecsSinceEpoch() and with my axis definition I get a good visual on the QChart of the time formatted in a way you can understand. I was able to work out from your tutorial how to use VectorXD where I used to use QLineSeries to plot my data but I can't seem to figure out a way to get a proper time axis on X. I do have a python version of my app that does use plotly which has a nice date axis, but on that one the app reads a csv and with pandas I can use parse_dates=(the one that's my time column) and plotly just works without me having to do anything. How do I do this with cpplot? Sorry for the rambling..

tdtooke avatar Feb 19 '21 22:02 tdtooke

Hi @tdtooke thanks for opening the issue!

I'd not really considered timeseries before (strange, I do a lot of timeseries work but I guess nothing in c++!).

Can you help me out and create a very minimal python example (just a few datapoints) that'll plot the kind of chart you want? That'd give me a clearer idea of exactly what's needed.

thclark avatar Feb 19 '21 22:02 thclark

Here's a little snippet that'll do a time axis on x with plotly

import pandas as pd import plotly.graph_objects as plotz

mydata = [['2020-07-07 18:24:26.703', 23.42968], ['2020-07-07 18:27:55.833', 68.20094], ['2020-07-07 18:31:55.823', 1.014660e+02]] df = pd.DataFrame(mydata, columns=['Time', 'Temp']) df['Time'] = pd.to_datetime(df['Time']) fig = plotz.Figure() fig.add_trace(plotz.Scatter(x = df['Time'], y = df['Temp'], name = "Test")) fig.write_html("test.html")

tdtooke avatar Feb 22 '21 17:02 tdtooke