Plotting x and y values with result as color / heatmap

Denver Dang

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):

enter image description here

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.

Stop harming Monica

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()

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Plotting sort of a heatmap whose colors are a result of a function x,y -> r,g,b

Plotting sorted heatmap keeping (x,y) value colors

Plotting Contours with x, y, z values

Plotting several Y values vs X

plotting with specific values for heatmap in pheatmap

Generate a heatmap in a set X, Y, Z with Z being the intensity of the color

How to set custom x and y tick values in a Makie heatmap

Plotting jaccard index with values inside the heatmap

Google Charts: Plotting mutiple "Y" values on same "X" value

Error when plotting y function with range of x values

Plotting two y-values for x=0 in a MS Chart control

Plotting multiple y-values versus x using Matplotlib

Plotting y values of an arc

Heatmap with just x (or y) axis

How to give color for x values and y values in linear regression model?

Excel - Plotting different y-values on top of same x-values

plotting with symbols on x and y axis

Plotting [x,y] using matplotlib

seaborn heatmap color scheme based on row values

Change color of missing values in Seaborn heatmap

Matplotlib: data not showing on the two sides in heatmap using x, y, z values stored in lists

Matplotlib: How does one plot a 1D array of x values with y-axis corresponding to a heatmap?

Plotting a function using Python where the x and y values are represented in terms of variables

Plotting a simple chart on Python Or R with X-Value(AGE), and Y-VALUES(HEIGHT and WEIGHT)

Matplotlib: Plotting all columns on the x-axis and values on the y-axis grouped by a third variable

Get x, y values of pixels of certain color with python PIL

Change color of X and Y axis values in Chart.js

Color columns based on x axis and not on values (y axis) in highcharts

Fill color for each area based on x and y start, end values