Absolutely! Matplotlib (which you’re using) is great for static plots, but for interactive plots with hover tooltips, you’ll want to use a library like Plotly or Bokeh. These libraries allow you to hover over points and see data values.
Here’s how you can do it with Plotly Express (the easiest way):
1. Using Plotly Express for ECDF with Hover
import plotly.express as px
# Assuming prefilled_sends is your DataFrame and 'prefill_size' is the column
fig = px.ecdf(
prefilled_sends,
x="prefill_size",
log_x=True, # log scale for x-axis
title="Cumulative distribution of prefill sizes in blocks",
labels={"prefill_size": "Prefill Size (bytes)"}
)
# Customize x-axis ticks and labels
fig.update_xaxes(
tickvals=[1, 1024, 10*1024, 100*1024, 1024*1024, 10*1024*1024],
ticktext=['1 B', '1 KB', '10 KB', '100 KB', '1 MB', '10 MB']
)
fig.show()
- Hovering over the plot will show you the x (prefill size) and y (cumulative percent) values.
- You can run this in a Jupyter notebook, or save as an HTML file to view in your browser.
2. Using Bokeh (Alternative)
If you prefer Bokeh:
from bokeh.plotting import figure, show
from bokeh.models import HoverTool, ColumnDataSource
import numpy as np
import pandas as pd
# Calculate ECDF
x = np.sort(prefilled_sends['prefill_size'])
y = np.arange(1, len(x)+1) / len(x) * 100
source = ColumnDataSource(data=dict(x=x, y=y))
p = figure(
title="Cumulative distribution of prefill sizes in blocks",
x_axis_type="log",
x_axis_label="Prefill Size (bytes)",
y_axis_label="Percent"
)
p.line('x', 'y', source=source)
p.circle('x', 'y', source=source, size=5, alpha=0.5)
hover = HoverTool(tooltips=[("Prefill Size", "@x"), ("Percent", "@y{0.2f}")])
p.add_tools(hover)
show(p)
Summary
- Matplotlib: Static, no hover.
- Plotly/Bokeh: Interactive, hover supported.
Recommendation:
If you want easy, beautiful, interactive plots with hover, use Plotly Express.
Let me know if you want a full example with your data!