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?

San9096
  • 231
  • 4
  • 12
  • `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. – JohanC May 15 '20 at 17:20
  • Yes, this was indeed very helpful, thank you @Georgy – San9096 May 15 '20 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')` – JohanC May 15 '20 at 17:35
  • This is what i was looking for, thank you @JohanC! – San9096 May 16 '20 at 09:57

1 Answers1

2

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

David
  • 424
  • 3
  • 16
  • 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? – San9096 May 15 '20 at 17:21