0

I am working on some mini project. I have array of x,y and want to connect all xy pairs with a number corresponding it's weight (like a heat map or sth). List of position is X,y pairs while the list of weights is list of numbers. My code look like this:

def plot_data(layer_num):
    t = list_of_postitions[layer_num]
    c = list_of_weights[layer_num]
    # we create matrix of x,y positions of spots
    r = np.reshape(t,(-1,2))
    print(np.shape(r))
    x, y = r.T
    plt.scatter(x,y)
    plt.title('Layer {}'.format(layer_num))
    plt.xlabel("X position")
    plt.ylabel("Y position")
    plt.show()

Thank you for your help

Robsztal
  • 3
  • 1

1 Answers1

0

According to pyplot documentation, you could use s parameter to change size of each point (if you want the plot size correspond to the weight) or c parameter to adapt color (there is tutorial that explain how to use it, one example here).

Both of s and c parameter could be an array with same length of position x and y.

Acsed.
  • 176
  • 1
  • 4
  • Np additional info: for the size it's easy, just `plt.scatter(x, y, s=c)`. I wrote `c` because i saw in your code this is how you call your 'list_of_weights'. For color, it's a little bit tricky as you have to use a [colormap](https://matplotlib.org/3.1.0/tutorials/colors/colormaps.html). Check this [answer](https://stackoverflow.com/questions/17682216/scatter-plot-and-color-mapping-in-python) too – Acsed. Apr 27 '20 at 14:40
  • it works like a charm even doing c=c but the diferences between weights are very little so i see very little change of color. Is there and option to nromalize it better automaticaly? – Robsztal Apr 27 '20 at 14:52
  • `plt.scatter(x, y, c=c, cmap='viridis')` should be ok. If I well remember, the colormap will fit with your min/max `c` values. You can use other registered colormap name instead of 'viridis'. – Acsed. Apr 27 '20 at 15:00
  • thank you Sir for your help. Now I can continue my project :) – Robsztal Apr 27 '20 at 15:04