Basically I have some x and y values. Each set of x and y values have a given value that corresponds to them. I am not sure a general seaborn
heatmap would suffice when wanting to do that (I might be mistaken), so what to do ?
I would like it to look something like this (including bins, so that it's a more "smooth" colored surface, and not just a lot of different colored dots all around):
EDIT: So I'll try to explain better.
Let's say I have something like this:
import numpy as np
nx = 3
ny = 5
x = np.linspace(0.1, 1, nx)
y = np.linspace(1, 11, ny)
x_bc = x[:, np.newaxis]
y_bc = y[np.newaxis, :]
z = x_bc * y_bc
The output of z
is then every combination of x
and y
, i.e.:
[[ 0.1 0.35 0.6 0.85 1.1 ]
[ 0.55 1.925 3.3 4.675 6.05 ]
[ 1. 3.5 6. 8.5 11. ]]
So in this case I have 3x5 z
-values, i.e. what should be the colors in the plot, and those values come from two lists (x
and y
) that has length 3 and 5 respectively. That is pretty much what I would like to plot.
Those lines look like contours. In order to draw them and have the spaces between them filled with colors you can use contourf
.
In order to make this work I had to transpose z
so that the number of columns match the size of x
and the number of rows match the size of y
.
nx = 3
ny = 5
x = np.linspace(0.1, 1, nx)
y = np.linspace(1, 11, ny)
x_bc = x[:, np.newaxis]
y_bc = y[np.newaxis, :]
z = x_bc * y_bc
plt.contourf(x, y, z.T)
plt.colorbar()
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments