AeroClassics
AeroClassics

Reputation: 1124

How to show a Holoviews Heatmap

I have a function that creates a Holoviewa heatmap. If I save the heatmap using hv.save(heatmap, 'heatmap.html') it works great! I just cannot figure out how to show the plot without having to save it. The same script generates two density plots with Plotly and using .show() and pops the plot up in my browser.

I am NOT using Jupyter Notebook and have been starting the bokeh server from a DOS prompt. I am working inside PyCharm Community with Python 3.10. Though if I could do it all from inside the script that would be easier.

def gen_heat_map(df: pandas.DataFrame, freq: float) -> holoviews.HeatMap:
    """
    Uses a single frequency upon which to build the heatmap.

    :param df: pandas.Dataframe containing data read from a JSON file
    :param freq: The frequency to build the heatmap out of
    :return: Holoviews Heat Map
    """
    # Select a single frequency upon which to build the heatmap
    single_frq = df[df.centerFrequency == freq].reset_index(drop=True)

    # create a second dataframe from each transmission
    sec_df = pd.DataFrame()
    for index, row in single_frq.iterrows():
        sec_df = sec_df.append(make_by_second(row), ignore_index=True)

    min_df = sec_df.set_index('time').resample('1min').mean().reset_index().replace(np.nan, -160)
    with pd.option_context('display.max_columns', None):
        print(min_df)

    min_df["Minute"] = min_df["time"].dt.strftime("%M")
    min_df["Hour"] = min_df['time'].dt.strftime("%H")

    heatmap = hv.HeatMap(min_df, ['Minute', 'Hour'], ['power', 'time'])
    heatmap.opts(radial=True,
                 width=750,
                 height=750,
                 tools=['hover'],
                 colorbar=True,
                 cmap='bokeh',
                 start_angle=-np.pi * 7 / 24,
                 title='Frequency Power Level Radial Heat Map'
                 )
    return heatmap

heatmap = gen_heat_map(df, 929612500.0)

The function gen_heat_map takes a large Pandas Dataframe of data read from a JSON file plus a single frequency and generates the heat map. It is trying to display this resultant heat map that is the issue. I can do so through Holoviz's Panel toolkit but I would like to find a simpler solution.

Upvotes: 0

Views: 308

Answers (0)

Related Questions