Reference for ultralytics/solutions/analytics.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/solutions/analytics.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.solutions.analytics.Analytics
Analytics(type, writer, im0_shape, title='ultralytics', x_label='x', y_label='y', bg_color='white', fg_color='black', line_color='yellow', line_width=2, points_width=10, fontsize=13, view_img=False, save_img=True, max_points=50)
A class to create and update various types of charts (line, bar, pie, area) for visual analytics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type |
str
|
Type of chart to initialize ('line', 'bar', 'pie', or 'area'). |
required |
writer |
object
|
Video writer object to save the frames. |
required |
im0_shape |
tuple
|
Shape of the input image (width, height). |
required |
title |
str
|
Title of the chart. |
'ultralytics'
|
x_label |
str
|
Label for the x-axis. |
'x'
|
y_label |
str
|
Label for the y-axis. |
'y'
|
bg_color |
str
|
Background color of the chart. |
'white'
|
fg_color |
str
|
Foreground (text) color of the chart. |
'black'
|
line_color |
str
|
Line color for line charts. |
'yellow'
|
line_width |
int
|
Width of the lines in line charts. |
2
|
points_width |
int
|
Width of line points highlighter |
10
|
fontsize |
int
|
Font size for chart text. |
13
|
view_img |
bool
|
Whether to display the image. |
False
|
save_img |
bool
|
Whether to save the image. |
True
|
max_points |
int
|
Specifies when to remove the oldest points in a graph for multiple lines. |
50
|
Source code in ultralytics/solutions/analytics.py
update_area
Update the area graph with new data for multiple classes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame_number |
int
|
The current frame number. |
required |
counts_dict |
dict
|
Dictionary with class names as keys and counts as values. |
required |
Source code in ultralytics/solutions/analytics.py
update_bar
Update the bar graph with new data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
count_dict |
dict
|
Dictionary containing the count data to plot. |
required |
Source code in ultralytics/solutions/analytics.py
update_line
Update the line graph with new data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frame_number |
int
|
The current frame number. |
required |
total_counts |
int
|
The total counts to plot. |
required |
Source code in ultralytics/solutions/analytics.py
update_multiple_lines
Update the line graph with multiple classes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
counts_dict |
int
|
Dictionary include each class counts. |
required |
labels_list |
int
|
list include each classes names. |
required |
frame_number |
int
|
The current frame number. |
required |
Source code in ultralytics/solutions/analytics.py
update_pie
Update the pie chart with new data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
classes_dict |
dict
|
Dictionary containing the class data to plot. |
required |
Source code in ultralytics/solutions/analytics.py
write_and_display
Write and display the line graph Args: im0 (ndarray): Image for processing