Reputation: 1275
Trying to resequence the heatmap such that y-axis actually runs from 0 to -19 under the x-axis (like a normal negative would descend downward).
Instead, regardless of sort order onto redim.values it "ascends" from 0 to -19 on the y-axis. See encircled axis in red.
from pathlib import Path
import holoviews as hv
import pandas as pd
import webbrowser
hv.extension('bokeh')
renderer = hv.renderer('bokeh')
data = [{"x": str(i),
"y": str(-j),
"z": i*j }
for i in range(20)
for j in range(20)]
df = pd.DataFrame(data)
# X works ok... or ok by happenstance
x_vals = list(set(df["x"].tolist()))
x_vals.sort(key=int)
# Y making no difference
y_vals1 = list(set(df["y"].tolist()))
y_vals1.sort(key=int, reverse=True)
y_vals2 = list(set(df["y"].tolist()))
y_vals2.sort(key=int, reverse=False)
hm1 = hv.HeatMap(df,
)
hm1.opts(hv.opts.HeatMap(tools=['hover'],
colorbar=True,
height=800,
width=800,
toolbar='above',
),
)
hm1.redim.values(
#x=x_vals,
y=y_vals1,
)
html = renderer.html(hm1)
Path("test_True.html").write_text(html,
encoding="utf-8")
webbrowser.open("test_True.html")
#-------------------------------------------------------------------------
hm2 = hv.HeatMap(df,
)
hm2.opts(hv.opts.HeatMap(tools=['hover'],
colorbar=True,
height=800,
width=800,
toolbar='above',
),
)
hm2.redim.values(
#x=x_vals,
y=y_vals2,
)
html = renderer.html(hm2)
Path("test_False.html").write_text(html,
encoding="utf-8")
webbrowser.open("test_False.html")
Upvotes: -1
Views: 41
Reputation: 1275
Ended up resorting to reordering of the data
Which gave me desired outcome in the MRE. Hopefully will apply through to my real use case. Haven't tried that just yet.
Perhaps someone more slick with holoviews will come up with an alternative that doesn't involve touching the original dataset?
(Probably no need to sort by x in the below, but it was coded as flexible for messing around.)
df2 = deepcopy(df)
df2["_x_index"] = df2.x.astype(int)
df2["_y_index"] = df2.y.astype(int)
df2 = df2.sort_values(by=["_y_index", "_x_index"],
ascending=[True, True],
)
hm3 = hv.HeatMap(df2,
)
hm3.opts(hv.opts.HeatMap(tools=['hover'],
colorbar=True,
height=800,
width=800,
toolbar='above',
)
),
html = renderer.html(hm3)
Path("test_df2.html").write_text(html,
encoding="utf-8")
webbrowser.open("test_df2.html")
Upvotes: -1