0
0
Matplotlibdata~5 mins

Marker size variation in Matplotlib - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Marker size variation
O(n)
Understanding Time Complexity

When we change marker sizes in a plot, the computer must draw each marker with its own size. We want to understand how the time to draw grows as we add more markers.

How does the drawing time increase when we vary marker sizes for many points?

Scenario Under Consideration

Analyze the time complexity of the following code snippet.


import matplotlib.pyplot as plt
import numpy as np

x = np.arange(1000)
y = np.random.rand(1000)
sizes = np.linspace(10, 200, 1000)

plt.scatter(x, y, s=sizes)
plt.show()
    

This code plots 1000 points with marker sizes changing from small to large.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: Drawing each marker with its specific size.
  • How many times: Once for each point, here 1000 times.
How Execution Grows With Input

Each new point adds one more marker to draw, so the total work grows as we add points.

Input Size (n)Approx. Operations
1010 marker draws
100100 marker draws
10001000 marker draws

Pattern observation: The drawing time grows directly with the number of points.

Final Time Complexity

Time Complexity: O(n)

This means the time to draw markers grows in a straight line as we add more points.

Common Mistake

[X] Wrong: "Changing marker sizes makes the drawing time grow faster than the number of points."

[OK] Correct: Each marker is drawn once regardless of size; size changes do not multiply the number of drawing steps.

Interview Connect

Understanding how drawing time grows with data size helps you explain performance in data visualization tasks clearly and confidently.

Self-Check

What if we added a loop to redraw each marker multiple times? How would the time complexity change?