1

I have two vectors of different length and their corresponding probabilities.

import numpy as np

x = np.arange(10)+1
y = np.arange(15)+10
px = np.random.normal(0.5,0.05,10)
py = np.random.normal(0.5,0.05,15)

I would like to make a 2D of x vs y where the plane is colored according to the probability of x and y.

I'm stuck on the fact that x and y are not of the same dimension. But in essence that should just give 'pixels' of different size in the x and y direction, no? Any suggestions are appreciated!

Riyaz
  • 1,430
  • 2
  • 17
  • 27
user3560311
  • 85
  • 2
  • 6

2 Answers2

4

Do you mean this kind of thing? extent=[x0, x1, y0, y1] is one way to override the scale of axes, found in this answer. There may be better or nicer ways.

import numpy as np
import matplotlib.pyplot as plt


x = np.arange(10)+1
y = np.arange(15)+10
px = np.random.normal(0.5,0.05,10)
py = np.random.normal(0.5,0.05,15)

p = px[None,:]*py[:,None]

plt.figure(figsize=[10,6])

plt.subplot(1,2,1)
plt.imshow(p, origin='lower', extent=[1,10, 10,24])
plt.colorbar()

plt.subplot(1,2,2)
plt.imshow(p, cmap='gray', vmin=0.1, vmax=0.4, interpolation=None,
           origin='lower', extent=[1,10, 10,24] )

plt.colorbar()

plt.savefig("twoDp")

plt.show()

enter image description here

Community
  • 1
  • 1
uhoh
  • 3,713
  • 6
  • 42
  • 95
1

There is nothing wrong with x and y not being of the same dimension. Most 2D plots do not have both axis in the same dimension. Matplotlib should handle this fine. When you plot it, you are taking particular values of x and y at a point, so the dimension is the same.

Untitled123
  • 1,317
  • 7
  • 20