Convert this to plotly: [code]
- User
Convert this to plotly:
python
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Convert this to plotly:
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
# Plot reconstruction time histogram and bytesmissing/reconstructiontime scatterplot
histcolor = "#749940"
prefiller_received['reconstruction_time_ms'] = prefiller_received['reconstruction_time_ns'] / 1_000_000
prefiller_received['were_bytes_missing?'] = np.where(prefiller_received['bytes_missing'] > 0, 'Yes', 'No')
f, [ax1, ax2] = plt.subplots(2, figsize=(10,10), tight_layout=True)
# Histplot on top
sns.histplot(data=prefiller_received, x='reconstruction_time_ms', hue='were_bytes_missing?', ax=ax1, color=histcolor, log_scale=2, bins=70)
ax1.xaxis.set_major_formatter(mpl.ticker.ScalarFormatter())
ax1.set_xticks([0.5, 1, 5, 50, 200, 1000])
cursor = Cursor(ax1, useblit=True, color='red', linewidth=1, alpha=0.1)
# Scatterplot on bottom "
scattercolor = "#994047"
xticks = [1, 10, 50, 100, 1000]
yticks_bytes = [0, 256, 1024, 10*1024, 1024*1024, 4*1024*1024] # 256B, 1KB, 10KB, 100KB, 1MB, 4MB
ytick_labels = ['0 B', '256 B', '1 KiB', '10 KiB', '1 MiB', '4 MiB']
sns.scatterplot(data=prefiller_received, x='reconstruction_time_ms', y='bytes_missing',
ax=ax2, color=scattercolor, alpha=0.3, s=30)
ax2.set_title('Scatter plot of Reconstruction Time/Missing Bytes')
ax2.set_xlabel('Reconstruction Time (ms)')
ax2.set_xticks(xticks)
ax2.set_xscale('log')
ax2.set_xlim(left=1)
ax2.xaxis.set_major_formatter(mpl.ticker.ScalarFormatter())
ax2.yaxis.set_major_formatter(mpl.ticker.ScalarFormatter())
ax2.set_ylim(-0.5)
ax2.set_ylabel('Missing Bytes')
ax2.set_yscale('symlog')
ax2.set_yticks(yticks_bytes)
ax2.set_yticklabels(ytick_labels)
plt.show()
Here's the plotly conversion of your matplotlib/seaborn code:
import plotly.graph_objects as go
import plotly.express as px
from plotly.subplots import make_subplots
import numpy as np
# Data transformations (same as original)
histcolor = "#749940"
prefiller_received['reconstruction_time_ms'] = prefiller_received['reconstruction_time_ns'] / 1_000_000
prefiller_received['were_bytes_missing?'] = np.where(prefiller_received['bytes_missing'] > 0, 'Yes', 'No')
# Create subplots
fig = make_subplots(
rows=2, cols=1,
subplot_titles=('Reconstruction Time Distribution', 'Scatter plot of Reconstruction Time/Missing Bytes'),
vertical_spacing=0.1
)
# Top subplot: Histogram
for category in ['No', 'Yes']:
data_subset = prefiller_received[prefiller_received['were_bytes_missing?'] == category]
fig.add_trace(
go.Histogram(
x=data_subset['reconstruction_time_ms'],
name=f'Bytes Missing: {category}',
opacity=0.7,
nbinsx=70,
marker_color=histcolor if category == 'No' else '#994047'
),
row=1, col=1
)
# Bottom subplot: Scatterplot
scattercolor = "#994047"
fig.add_trace(
go.Scatter(
x=prefiller_received['reconstruction_time_ms'],
y=prefiller_received['bytes_missing'],
mode='markers',
name='Data Points',
marker=dict(
color=scattercolor,
opacity=0.3,
size=5
),
showlegend=False
),
row=2, col=1
)
# Update x-axis for both subplots (log scale)
fig.update_xaxes(
type="log",
tickvals=[0.5, 1, 5, 50, 200, 1000],
ticktext=["0.5", "1", "5", "50", "200", "1000"],
title_text="Reconstruction Time (ms)",
row=1, col=1
)
fig.update_xaxes(
type="log",
tickvals=[1, 10, 50, 100, 1000],
ticktext=["1", "10", "50", "100", "1000"],
title_text="Reconstruction Time (ms)",
range=[0, 3], # log10(1) to log10(1000)
row=2, col=1
)
# Update y-axis for histogram
fig.update_yaxes(
title_text="Count",
row=1, col=1
)
# Update y-axis for scatterplot (symlog scale approximation)
yticks_bytes = [0, 256, 1024, 10*1024, 1024*1024, 4*1024*1024]
ytick_labels = ['0 B', '256 B', '1 KiB', '10 KiB', '1 MiB', '4 MiB']
fig.update_yaxes(
type="log",
tickvals=yticks_bytes,
ticktext=ytick_labels,
title_text="Missing Bytes",
range=[-0.5, 6.5], # Approximate range for the data
row=2, col=1
)
# Update layout
fig.update_layout(
height=800,
width=800,
showlegend=True,
title_text="Reconstruction Time Analysis"
)
fig.show()
Key changes from matplotlib to plotly:
make_subplots() instead of plt.subplots()go.Scatter() with markers modetype="log" in axis updatestickvals and ticktext parametersThe plotly version will be interactive by default, allowing you to zoom, pan, and see hover information without needing the matplotlib cursor functionality.