Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plotting heatmap for 4 variables #104

Closed
Rajat-Mehta opened this issue Apr 16, 2019 · 1 comment
Closed

Plotting heatmap for 4 variables #104

Rajat-Mehta opened this issue Apr 16, 2019 · 1 comment

Comments

@Rajat-Mehta
Copy link

Rajat-Mehta commented Apr 16, 2019

Hi team,

Thanks for your work. I am facing some problem with plotting heatmaps.

I have list as shown below:
[ [0.2, 0.4,0.4, 0.90], [0.5, 0.1,0.4, 0.59], [0.3, 0.6,0.1, 0.87] ......, [0.4, 0.3,0.3, 0.95] ]

where the first three indexes are some parameters of my machine learning model and 4th is the accuracy value.
I want to plot triangular heat map, where each point inside the triangle is represented by the first three indexes of my list and each of those points have a heat value of: 4th index in my list.

This is what I tried :

def color_point_new(x, y, z, m):
    w = 255
    print(x,y,z)
    m_color = float(m) * w/255
    r = math.fabs(w - m_color) / w
    g=0
    b=0
    print(m_color)
    return (m_color, g, b, 1.)

def generate_heatmap_data_new(scale=5):
    d = dict()
    X = [0.2,0.3,0.4,0.5]
    Y = [0.5,0.6,0.5,0.1]
    Z = [0.3,0.1,0.1,0.4]
    M = [0.67,0.87,0.78,0.90]
    for i in range(len(X)):
        total = X[i] + Y[i] + Z[i]
        x_norm = X[i] / total
        y_norm = Y[i] / total
        z_norm = Z[i] / total
        d[(X[i], Y[i], Z[i])] = color_point_new(x_norm, y_norm, z_norm, M[i])
    return d

scale = 1
data = generate_heatmap_data_new(scale)
figure, tax = ternary.figure(scale=scale)
tax.heatmap(data, style="hexagonal", use_rgba=True, colorbar=False)
tax.clear_matplotlib_ticks()
tax.get_axes().axis('off')
tax.boundary()
tax.set_title("RGBA Heatmap")
plt.show()

I want to show high heat value (may be in red color) when there is high accuracy and low heat value when the accuracy value is less.

I am not able to figure out how to achieve this. Any help will be much appreciated.

Thanks in advance.
Rajat

``

@marcharper
Copy link
Owner

Hi, apologies for not seeing this until now. You basically want an interpolated heatmap, which the library doesn't directly support. You need to interpolate the values yourself and the use heatmapf to plot the resulting function. See #81 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants