Visualizing API Response Times with Python Plotly Distplot
This guide shows how to use Python and Plotly to create a distplot—combining a histogram and density curve—to visualize API response time data read from a log file, complete with a ready‑to‑run script and sample output image.
Overview
During API testing the author switched from violin plots to a distplot, which shows integer‑based histograms with an overlaid smooth curve to illustrate response‑time distributions.
Implementation
The Python script uses plotly.plotly, plotly.figure_factory (aliased as fff) and numpy. A Distplots class defines an initializer that prints a confirmation message and a makeDistplot method that creates the chart with fff.create_distplot and saves it as an HTML file via plotly.offline.plot.
Data preparation
In the __main__ block three synthetic data series are generated with np.random.randn, scaled, and combined with real‑world data read from a log file ( /Users/Vicky/Documents/workspace/fission/long.log). Each line is converted to float, filtered to keep values ≤ 1, multiplied by 100, and collected into a list xy. This list becomes data1 with a single group label "test1". An instance of Distplots then calls makeDistplot to produce 3333.html.
Key code
#!/usr/bin/python
# coding=utf-8
import plotly.plotly
import plotly.figure_factory as fff
import numpy as np
class Distplots:
def __init__(self):
print("distplots图标生成!")
def makeDistplot(self, data, group):
fig = fff.create_distplot(data, group)
plotly.offline.plot(fig, filename="3333.html")
if __name__ == "__main__":
x = np.random.randn(1000) * 10
y = np.random.randn(1000) * 10 + 50
z = np.random.randn(1000) * 10 + 100
data = [x, y, z]
group = ["one", "two", "three"]
xy = []
with open("/Users/Vicky/Documents/workspace/fission/long.log", "r") as f:
for line in f.readlines():
t = float(line)
if t > 1:
continue
xy.append(t)
xy = [v * 100 for v in xy]
data1 = [xy]
group1 = ["test1"]
drive = Distplots()
drive.makeDistplot(data1, group1)Result
The generated HTML file contains a distplot that visualizes the distribution of API response times, allowing engineers to assess performance characteristics quickly.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
