MatPlotLib connected wrong datapoint

17 Views Asked by At

I have this simple boto3 code to get CPU ultilization for instances. The data i get was correct but somehow the way Matplotlib displaying my data is wrong.

plt.figure(figsize=(10, 6))
        plt.scatter(timestamps, cpu_values)
        plt.plot(timestamps, cpu_values, marker='o', markersize=3) 
        plt.xlabel('Time')
        plt.ylabel('CPU Utilization (%)')
        plt.title('CPU Utilization for EC2 Instance: ' + instance_id)
        plt.grid(True)
        plt.xticks(rotation=45)
        # plt.tight_layout()
        plt.savefig('cpu_utilization_plot.png')  # Save the plot as an image
        plt.show() 

This is how i plot and the output is this:enter image description here

Instead of like this:

enter image description here (ref picture: GeeksForGeeks)

Where am i doing wrong?

0

There are 0 best solutions below