Skip to content

Blank Heatmap #197

@sdebesai

Description

@sdebesai

Hi,

First I wanted to say thank you for creating such a well documented and useful package. I am attempting to use the heatmap() function but my current output is just a blank plot and I'm having trouble understanding why. I tried creating a dictionary where I mapped points to random values instead of the actual data I'm attempting to plot to see if it was an issue with my data but that's not working either. I think I'm likely doing something silly (maybe in my data generation?) but am pretty stuck and would appreciate any insight. As a note I'm omitting the boundaries where a coordinate is 0 because the distribution I hope to eventually plot behaves weirdly there, but this is something I intend to address later. Here's the code snippet:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import ternary
import random

def gen_rand_data(f1_list_all=np.linspace(0,1,100)):
data = {}
for f1 in f1_list_all:
if f1 != 0:
f2_list=f1_list_all[np.where(f1_list_all< 1-f1)]
f1_list=f1*np.ones(f2_list.shape[0])

        for f2 in f2_list:
            if f2 > 0:
                val=random.uniform(0, 1)
                data[(f1, f2)] = val
                color=ternary.colormapping.colormapper(val) #testing to see that function converts to colors.
                print(color)
#print(data)
return data

def main():
f1_list_all=np.linspace(0,1,100)
#data, Z=gen_data(f1_list_all)
data = gen_rand_data(f1_list_all=np.linspace(0,1,100))

scale = 1

fig, ax = plt.subplots()
ax.axis("off")
figure, tax = ternary.figure(ax=ax, scale=scale)

tax.heatmap(data, cmap=None)

axes_colors = {'b': 'g', 'l': 'r', 'r': 'b'}
tax.boundary(linewidth=2.0)

tax.left_axis_label("$f_1$", offset=0.16)
tax.right_axis_label("$f_2$", offset=0.16)
tax.bottom_axis_label("$f_3$", offset=0.06)

tax.gridlines(multiple=1, linewidth=2,
          horizontal_kwargs={'color': axes_colors['b']},
          left_kwargs={'color': axes_colors['l']},
          right_kwargs={'color': axes_colors['r']},
          alpha=0.7)

# Set and format axes ticks.
ticks = [i / float(scale) for i in range(scale+1)]
tax.ticks(ticks=ticks, axis='rlb', linewidth=1, clockwise=True,
      axes_colors=axes_colors, offset=0.03, tick_formats="%0.1f")

tax.clear_matplotlib_ticks()
tax._redraw_labels()
plt.tight_layout()
tax.show()
figure.savefig('simplex_plot.png')

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions