def hexTilePlot(): p = figure( title="Hex Tiles Plot", sizing_mode="fixed", plot_width=400, plot_height=400, toolbar_location=None, ) q = np.array([0, 0, 0, -1, -1, 1, 1]) r = np.array([0, -1, 1, 0, 1, -1, 0]) p.grid.visible = False p.hex_tile( q, r, size=1, fill_color=["firebrick"] * 3 + ["navy"] * 4, line_color="white", alpha=0.5, ) x, y = axial_to_cartesian(q, r, 1, "pointytop") p.text( x, y, text=["(%d, %d)" % (q, r) for (q, r) in zip(q, r)], text_baseline="middle", text_align="center", ) return p
def hexbin(x, y, ids, size, aspect_scale, orientation): ''' This function recieves x, y coordinates arrays and turns these into q, r hexagon coordinates returned in a pandas dataframe. Additionally, the center x, y coordinates for every hexagon are added. ''' q, r = cartesian_to_axial(x, y, size, orientation=orientation, aspect_scale=aspect_scale) x, y = axial_to_cartesian(q, r, size, orientation=orientation, aspect_scale=aspect_scale) df = pd.DataFrame(dict(r=r, q=q, x=x, y=y)) df['ids'] = ids df = df.groupby(['q', 'r', 'x', 'y'])['ids'].apply(list).reset_index(name='ids') counts = [] for row in df['ids']: counts.append(len(row)) df['counts'] = counts return df
def test_default_aspect_flattop(self): q = np.array([0, 0, 0, 1, -1, 1, -1]) r = np.array([0, 1, -1, 0, 1, -1, 0]) x, y = buh.axial_to_cartesian(q, r, 1, "flattop") sq3 = np.sqrt(3) assert list(x) == [0.0, 0.0, 0.0, 1.5, -1.5, 1.5, -1.5] assert list(y) == [0, -sq3, sq3, -sq3 / 2, -sq3 / 2, sq3 / 2, sq3 / 2]
def test_default_aspect_pointytop(self) -> None: q = np.array([0, 0, 0, 1, -1, 1, -1]) r = np.array([0, 1, -1, 0, 1, -1, 0]) x, y = buh.axial_to_cartesian(q, r, 1, "pointytop") sq3 = np.sqrt(3) assert list(x) == [0, sq3 / 2, -sq3 / 2, sq3, -sq3 / 2, sq3 / 2, -sq3] assert list(y) == [-0.0, -1.5, 1.5, -0.0, -1.5, 1.5, -0.0]
def test_default_aspect_flattop(self): q = np.array([0, 0, 0, 1, -1, 1, -1]) r = np.array([0, 1, -1, 0, 1, -1, 0]) x, y = buh.axial_to_cartesian(q, r, 1, "flattop") sq3 = np.sqrt(3) assert list(x) == [0.0, 0.0, 0.0, 1.5, -1.5, 1.5, -1.5] assert list(y) == [0, -sq3, sq3, -sq3/2, -sq3/2, sq3/2, sq3/2]
def draw(self): self.plot.hex_tile(self.qs, self.rs, fill_color=self.colors, alpha=0.5, line_color="white", orientation="flattop") x, y = axial_to_cartesian(self.qs, self.rs, 1, "flattop") self.plot.text(x, y, text=self.indices, text_baseline="middle", text_align="center")
import numpy as np from bokeh.io import output_file, show from bokeh.plotting import figure from bokeh.util.hex import axial_to_cartesian output_file("hex_coords.html") q = np.array([0, 0, 0, -1, -1, 1, 1]) r = np.array([0, -1, 1, 0, 1, -1, 0]) p = figure(plot_width=400, plot_height=400, toolbar_location=None) p.grid.visible = False p.hex_tile(q, r, size=1, fill_color=["firebrick"]*3 + ["navy"]*4, line_color="white", alpha=0.5) x, y = axial_to_cartesian(q, r, 1, "pointytop") p.text(x, y, text=["(%d, %d)" % (q,r) for (q, r) in zip(q, r)], text_baseline="middle", text_align="center") show(p)
import numpy as np from bokeh.io import output_file, show from bokeh.plotting import figure from bokeh.util.hex import axial_to_cartesian output_file("hex_coords.py") q = np.array([0, 0, 0, -1, -1, 1, 1]) r = np.array([0, -1, 1, 0, 1, -1, 0]) p = figure(plot_width=400, plot_height=400, toolbar_location=None) p.grid.visible = False p.hex_tile(q, r, size=1, fill_color=["firebrick"]*3 + ["navy"]*4, line_color="white", alpha=0.5) x, y = axial_to_cartesian(q, r, 1, "pointytop") p.text(x, y, text=["(%d, %d)" % (q,r) for (q, r) in zip(q, r)], text_baseline="middle", text_align="center") show(p)
def axial_to_cartesian(vector): cartesian = b.axial_to_cartesian(vector[0], vector[1], 1, "flattop") return np.array(cartesian)
# heatmaps Graphs #hex tile map colMapper = LinearColorMapper(palette=Spectral11, low=skelViewData.abs_dsplc.min(), high=skelViewData.abs_dsplc.max()) bodyHM = figure(plot_width=540,plot_height=290, toolbar_location=None) bodyHM.xaxis.visible = False bodyHM.yaxis.visible = False bodyHM.grid.visible = False bodyHM.hex_tile(q='hexCoordQ', r='hexCoordR', size=1, source=tableSource, fill_color=transform('abs_dsplc', colMapper), name="bodyHMHexTile", line_color="black", line_width=1, alpha=0.9) x, y = axial_to_cartesian(skelViewData.hexCoordQ, skelViewData.hexCoordR, 1, "pointytop") bodyHM.text(x=x, y=y, text=[str(coord) for coord in skelViewData.name_es], text_baseline="middle", text_align="center", text_color="black", text_font_size="10px") color_bar = ColorBar(color_mapper=colMapper, name="bodyHMColorMap",#ticker=LogTicker(), BasicTicker label_standoff=5, major_label_text_color="gray", border_line_color=None, location=(0,0)) bodyHM.add_layout(color_bar, 'right') bodyHMColbar=bodyHM.select({"name":"bodyHMColorMap"}) bodyHMHexTile=bodyHM.select({"name":"bodyHMHexTile"}) #Freq image map maxF=len(powF_body)//4 Fmax=(Fs/2)/4 peak_ceil=3.5 fqImage_raw=np.matrix([powF_rF[0:maxF], powF_rK[0:maxF], powF_rW[0:maxF],