2

I'm trying to some features to my Matplotlib chart, i wanted to create a series of small squares on different part of the chart.

Here is what the docs say: The example below illustrates plotting several lines with different format styles in one command using arrays.

import numpy as np

# evenly sampled time at 200ms intervals
t = np.arange(0., 5., 0.2)

# red dashes, blue squares and green triangles
plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
plt.show()

My problem is: i don't need a line of squares, i only need to add one at a certain place of X, Y coordinates, but the issue i'm having is finding a way to make it smaller, here is what i tried:

plt.plot(138, 9400, 'bs',linewidth=1.0)

I tried to set linewidth to different values, but nothing changes. The docs are a bit vague on this, can anyone tell me how can i set width, height and color of the squares?

4
  • plt.scatter(x,y, marker='s', c='b', s=10). The s= parameter controls the size. Note that it is relative to the area of the little square, not to the side length. Also, the size is relative to screen space, not to the data as displayed in the axes. Commented May 15, 2020 at 17:20
  • Yes, this was indeed very helpful, thank you @Georgy Commented May 15, 2020 at 17:26
  • 1
    For very small markers you need to use the comma marker (which happens to be a tiny square) and set the edgecolor to none. You need a lot of dots if you want to seem something when s is very small plt.scatter(np.random.rand(100000), np.random.rand(100000), marker=',', c='b', s=0.001, ec='none') Commented May 15, 2020 at 17:35
  • This is what i was looking for, thank you @JohanC! Commented May 16, 2020 at 9:57

1 Answer 1

2

use plot.scatter(x,y, marker='s', c='b') to put a blue square at x,y

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! The only problem is that the minimum value for it (0.1) is still too big for what i need, is there any way to make it even smaller?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.