Code/preprocess

draw_graph

Shy_un 2023. 11. 29. 17:07

막대그래프

import matplotlib.pyplot as plt
import numpy as np

# Data for plotting
models = ['1', '2', '3', '4'] #model name
metric = [0.561, 0.461, 0.69, 0.89] #metric

x = np.arange(len(models))  # the label locations
width = 0.35  # the width of the bars

fig, ax = plt.subplots()
rects1 = ax.bar(x, metric, width) 

# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('MOTA')
ax.set_title('Vehicle') #vehicle, pedestrian, ...
ax.set_xticks(x)
ax.set_xticklabels(models)
ax.legend()

# Attach a text label above each bar in *rects*, displaying its height.
def autolabel(rects):
    for rect in rects:
        height = rect.get_height()
        ax.annotate('{}'.format(height),
                    xy=(rect.get_x() + rect.get_width() / 2, height),
                    xytext=(0, 3),  # 3 points vertical offset
                    textcoords="offset points",
                    ha='center', va='bottom')

autolabel(rects1)

fig.tight_layout()

plt.show()

XY 그래프

import matplotlib.pyplot as plt
import numpy as np

# Data for plotting
models = ['AB3DMOT', '2', '3', '4']
mota_values = [0.561, 0.559, 0.546, 0.561]
id_switch_values = [0.13, 0.12, 0.07, 0.08]

# Define colors and markers for each model
colors = ['green', 'blue', 'orange', 'red']
markers = ['o', '^', 's', '*']

x_range = (0.540, 0.565)  # For MOTA
y_range = (0.00, 0.200)   # For IDs Switch

# Create scatter plot
fig, ax = plt.subplots()
for i in range(len(models)):
    ax.scatter(mota_values[i], id_switch_values[i], alpha=1, c=colors[i], marker=markers[i], label=models[i])

# Customize the plot
ax.set_title('Vehicle')
ax.set_xlabel('MOTA')
ax.set_ylabel('IDs Switch')

# Set the range for the axes
ax.set_xlim(x_range)
ax.set_ylim(y_range)

ax.grid(True, linestyle='--')

# Annotate each point with its MOTA and ID Switch values
for i, model in enumerate(models):
    ax.annotate(f"({mota_values[i]}, {id_switch_values[i]})",
                (mota_values[i], id_switch_values[i]),
                textcoords="offset points",
                xytext=(0,-15),
                ha='center')

# Add legend
ax.legend()

# Show the plot
plt.show()