0

I have some data in the form of data[time] = list of y values.
(data example: data = [[1, 2, 3], [1, 2], [5, 6, 7, 8]])

I want to plot that data using matplotlib in a way that every y value will be a dot (square) in the position (time, y).
Currently I'm using matplotlib.pyplot.scatter to do so
( plt.scatter(x = [time]*len(data[time]), y = data[time], s=5, marker='s') ), but the problem is that every square's height is too short, while the width is fine.

Is there a way to control the square's height separately and not both width and height with s? (scatter is not required, every plotting way is acceptable)

Example plot:

example plot

You can see there are vertical spaces between the squares, while there aren't any horizontal spaces.

Yuval.R
  • 1,182
  • 4
  • 15
  • `plt.axis('equal')` would make your plot have the same distances in x and in y. Instead of a scatter plot, you could use `plt.pcolor()` with a 2d array which has zero when there is no value, and 1 when there is a value (or maybe even different values, as your image seems to squares with different colors). – JohanC Dec 29 '21 at 16:07
  • About `plt.axis`, it doesn't work good here as it just puts all the data in one thin "pipe", but I'll check about `plt.pcolor`, thanks. – Yuval.R Dec 29 '21 at 16:08
  • Lots of good answers here: [Plotting a 2D heatmap with Matplotlib](https://stackoverflow.com/questions/33282368/plotting-a-2d-heatmap-with-matplotlib) – Bill Dec 29 '21 at 17:17
  • Interesting, will check. – Yuval.R Dec 29 '21 at 18:03

0 Answers0