-
-
Notifications
You must be signed in to change notification settings - Fork 261
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
Interactive graph example #492
Interactive graph example #492
Conversation
Hi, this looks really cool! I have two things to note for now. First, as you mentioned as well, I think it might be preferable to not define a custom plotly template. In my opinion, it makes the example a bit too bloated. Second, the example is currently not rendered correctly in the docs. There is no plotting output shown. You can compare your code to |
Sure, it's better to use a built-in template.
Fixed as the example, thanks! |
Also, I noticed it was not quite friendly having on the first render all of the drivers shown. |
The example is still not being rendered correctly in the documentation. I'm not really sure why that is the case, without digging any further right now. Ideally, you could try to build the documentation locally as that would be the quickest way to figure this out. Alternatively, the CI generates the documentation as a build artifact that you can download from the CI run summary. But this being your first pull request, I need to manually approve each CI run for every new change that you push. So this slows things down quite a bit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need the filename to start with "plot_" for Sphinx-Gallery to run the file and get the graph. See https://sphinx-gallery.github.io/stable/configuration.html#parsing-and-executing-examples-via-matching-patterns
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To execute this file, the filename should start with "plot_"
fig.update_xaxes(range=[0, max_range_x], | ||
showgrid=False, | ||
showline=False) | ||
############################################################################### |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually can stop right here. Sphinx-Gallery needs the last line to be a plotly Figure object, and fig.update_xaxes
already returns a Figure obj. See https://sphinx-gallery.github.io/stable/configuration.html#parsing-and-executing-examples-via-matching-patterns.
If we add fig; show(fig)
below, we will get a second/duplicate graph
import plotly.graph_objects as go | ||
from plotly.io import show | ||
|
||
# SETTING UP THE DATA ######################################################### |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments/explanation doesn't render. The expected format is:
##############################################################################
# Setting up the data
# Some other notes
print('python code here')
# Also, we have to define the number of laps for getting a nice x axis. | ||
# We're picking 0 for start and last lap number + 1 | ||
howmany_laps = race.laps['LapNumber'].max() | ||
max_range_x = howmany_laps + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the notorious pandas SettingWithCopyWarning here... Suppress the warning or use a copy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong line, I think, should be L47-48
# slowest lap of the quick laps and we're defining a margin of 0'5s for the | ||
# limits of the graph. | ||
quicklaps = race.laps.pick_quicklaps() | ||
quicklaps['LapTime(s)'] = quicklaps['LapTime'].dt.total_seconds() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.pick_quicklaps
returns a slice of the entire laps data. Therefore, setting quicklaps['LapTime(s)']
sets the new column of a copy of that slice which triggers the pandas warning.
Either, use race.laps.pick_quicklaps().copy()
or just don't set the lap time in seconds as a new column. It could just be its own variable.
Please do not suppress the warning, that's just confusing as well.
Hi!
I made an example of interactive graphs for displaying data using plotly
The example shows laptime evolution during a race and can be filtered to compare different drivers.
As I was not sure if there was a plotly supported template, I made a custom one, but it can be removed and replaced by default plotly templates (I recommend using dark ones).
I also have a jupyter notebook version of the example, and a py script that exports the graph into an interactive html file.
Here are some screenshots of the graph: