docs/en/guides/analytics.md
Analytics with Ultralytics YOLO26 turns object detection and tracking results into real-time charts, so you can watch how object counts change across a video frame by frame. This guide covers four data visualization types — line graphs, bar plots, pie charts, and area plots — and shows how to switch between them with shared Python and CLI examples.
<p align="center"> <iframe loading="lazy" width="720" height="405" src="https://www.youtube.com/embed/tVuLIMt4DMY" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen> </iframe><strong>Watch:</strong> How to generate Analytical Graphs using Ultralytics | Line Graphs, Bar Plots, Area and Pie Charts
</p>| Line Graph | Bar Plot | Pie Chart |
|---|---|---|
Pass your video to the Analytics solution and select a chart with analytics_type. The solution runs detection and tracking on every frame and renders a 1280×720 chart (by default) you can write straight to an output video. Switch between "line", "bar", "pie", and "area" with a single argument.
!!! example "Analytics using Ultralytics YOLO"
=== "CLI"
```bash
yolo solutions analytics show=True
# Pass the source
yolo solutions analytics source="path/to/video.mp4"
# Generate the pie chart
yolo solutions analytics analytics_type="pie" show=True
# Generate the bar plots
yolo solutions analytics analytics_type="bar" show=True
# Generate the area plots
yolo solutions analytics analytics_type="area" show=True
```
=== "Python"
```python
import cv2
from ultralytics import solutions
cap = cv2.VideoCapture("path/to/video.mp4")
assert cap.isOpened(), "Error reading video file"
# Video writer
w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))
out = cv2.VideoWriter(
"analytics_output.avi",
cv2.VideoWriter_fourcc(*"MJPG"),
fps,
(1280, 720), # this is fixed
)
# Initialize analytics object
analytics = solutions.Analytics(
show=True, # display the output
analytics_type="line", # pass the analytics type, could be "pie", "bar" or "area".
model="yolo26n.pt", # path to the YOLO26 model file
# classes=[0, 2], # display analytics for specific detection classes
)
# Process video
frame_count = 0
while cap.isOpened():
success, im0 = cap.read()
if success:
frame_count += 1
results = analytics(im0, frame_count) # update analytics graph every frame
# print(results) # access the output
out.write(results.plot_im) # write the video file
else:
break
cap.release()
out.release()
cv2.destroyAllWindows() # destroy all opened windows
```
Analytics ArgumentsHere's a table outlining the Analytics arguments:
{% from "macros/solutions-args.md" import param_table %} {{ param_table(["model", "analytics_type"]) }}
You can also leverage different track arguments in the Analytics solution.
{% from "macros/track-args.md" import param_table %} {{ param_table(["tracker", "conf", "iou", "classes", "verbose", "device"]) }}
Additionally, the following visualization arguments are supported:
{% from "macros/visualization-args.md" import param_table %} {{ param_table(["show", "line_width"]) }}
Understanding when and how to use different types of visualizations is crucial for effective data analysis. Line graphs, bar plots, and pie charts are fundamental tools that can help you convey your data's story more clearly and effectively. The Ultralytics YOLO26 Analytics solution provides a streamlined way to generate these visualizations from your object detection and tracking results, making it easier to extract meaningful insights from your visual data.
To create a line graph using Ultralytics YOLO26 Analytics, follow these steps:
Analytics class with analytics_type="line".results.plot_im to an output video to save the chart.Use the Python example above as a starting point — it already runs the full frame loop, and a line graph is the default analytics_type.
Using Ultralytics YOLO26 for creating bar plots offers several benefits:
To generate a bar plot, set analytics_type="bar" in the Python example above — the rest of the frame loop is identical. See the Visual Samples section for a preview.
Ultralytics YOLO26 is an excellent choice for creating pie charts because:
To generate a pie chart, set analytics_type="pie" in the Python example above. For more information, refer to the Visual Samples section in the guide.
Yes. Tracking is built into the Analytics solution: it tracks multiple objects in real time and updates the chart from the tracked objects' data every frame, so line graphs, bar plots, pie charts, and area plots all reflect live counts. This is exactly what the frame loop in the Python example above does. To learn about the underlying tracking functionality, see the Tracking section.
Ultralytics YOLO26 stands out from other object detection solutions like OpenCV and TensorFlow for multiple reasons:
For more detailed comparisons and use cases, explore our Ultralytics Blog.