def set_theme(cls, theme: themes.LayoutTheme = themes.LayoutTheme.DARK): """ Activate Restyling :param theme: """ hv.extension('bokeh') hv.renderer('bokeh').theme = Theme(json=cls.build_theme(theme)) cls.set_defaults()
def change_theme(style_name): theme_path = 'mcod.pn_apps.bokeh.themes.' try: theme_file_name = style_name.replace('-', '_') full_path = theme_path + theme_file_name selected_theme = locate(full_path) json_theme = selected_theme.json except AttributeError: json_theme = {} hv.renderer('bokeh').theme = Theme(json=json_theme)
def test_theme_rendering(self): theme = Theme( json={'attrs': { 'Figure': { 'outline_line_color': '#444444' } }}) self.renderer.theme = theme plot = self.renderer.get_plot(Curve([])) self.renderer.components(plot, 'html') self.assertEqual(plot.state.outline_line_color, '#444444')
def test_theme_rendering(self): theme = Theme( json={'attrs': { 'Figure': { 'outline_line_color': '#444444' } }}) renderer = BokehRenderer.instance(fig='png') renderer.theme = theme plot = renderer.get_plot(Curve([])) renderer(plot) self.assertEqual(plot.state.outline_line_color, '#444444')
def test_theme_rendering(self): theme = Theme( json={ 'attrs' : { 'Figure' : { 'outline_line_color': '#444444'} } }) self.renderer.theme = theme plot = self.renderer.get_plot(Curve([])) diff = self.renderer.diff(plot) events = [e for e in diff.content['events'] if e.get('attr', None) == 'outline_line_color'] self.assertTrue(bool(events)) self.assertEqual(events[-1]['new']['value'], '#444444')
def set_elvis_style(cls, theme: LayoutTheme = LayoutTheme.dark): hv.extension('bokeh') hv.renderer('bokeh').theme = Theme(json=cls.style(theme)) cls.curve_defaults() cls.point_defaults()
from bokeh.document import Document from bokeh.io import curdoc from bokeh.models import Model from bokeh.themes.theme import Theme from panel.io.notebook import render_mimebundle from param.parameterized import bothmethod from ...core import Store, HoloMap from ..plot import Plot from ..renderer import Renderer, MIME_TYPES, HTML_TAGS from .util import compute_plot_size default_theme = Theme(json={ 'attrs': { 'Title': { 'text_color': 'black', 'text_font_size': '12pt' } } }) class BokehRenderer(Renderer): backend = param.String(default='bokeh', doc="The backend name.") fig = param.ObjectSelector(default='auto', objects=['html', 'json', 'auto', 'png'], doc=""" Output render format for static figures. If None, no figure rendering will occur. """)
def build_dashboard(tweets, predictions_streamz_df): """Build the dashboard. changes the css, styles and creates empty place holders for tables, tweets and graphs """ template = """ {% extends base %} <!-- goes in body --> {% block postamble %} <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootswatch/4.5.0/solar/bootstrap.min.css"> {% endblock %} <!-- goes in body --> {% block contents %} {{ app_title }} <p/> <p style="text-align:center;"> <img src="https://user-images.githubusercontent.com/4336187/87214331-6d9ef280-c2f9-11ea-9c87-231f5c828a4e.png" height='108'> </p> <br> <div class="container"> <div class="row"> <div class="col-sm"> {{ embed(roots.B) }} </div> </div> <div class="container"> <div class="row"> <div class="col-sm"> {{ embed(roots.C) }} </div> </div> </div> </div> {% endblock %} <div style="background:<%= (function colorfromint(){ if(cola > colb ){ return("green")} }()) %>; color: black"> <%= value %> </div> """ css = ''' .panel-widget-box { background: #f0f0f0; border-radius: 5px; border: 1px black solid; } ''' theme = Theme( json={ 'attrs': { 'Figure': { 'background_fill_color': 'black', 'border_fill_color': 'black', 'outline_line_color': '#444444', }, 'Grid': { 'grid_line_dash': [6, 4], 'grid_line_alpha': .3, }, 'Axis': { 'major_label_text_color': 'white', 'axis_label_text_color': 'white', 'major_tick_line_color': 'white', 'minor_tick_line_color': 'white', 'axis_line_color': "white" } } }) hv.renderer('bokeh').theme = theme dashboard = pn.Template(template) tweets_table = pn.Column("##### Live Tweet Sentiments:", tweets.hvplot.table( columns=[ 'created_at', 'user_name', 'tweets', 'sentiments', 'polarity' ], backlog=10, ).opts(bgcolor='blue', height=272), css_classes=['panel-widget-box']) price = pn.Column( "##### Pricing Model", predictions_streamz_df.hvplot.line(width=1400, grid=True, backlog=500, title="prices").opts( bgcolor='black', legend_position='right')) positive_cloud = pn.Column( "##### Postive Word Cloud:", pn.pane.PNG('Images/postive_sentiments.png', height=272)) negative_cloud = pn.Column( "##### Negative Word Cloud:", pn.pane.PNG('Images/negative_sentiments.png', height=272)) clouds = pn.Row(positive_cloud, negative_cloud) sentiments = pn.Row(tweets_table, clouds) # dashboard.add_panel('B',tweets_table) dashboard.add_panel('B', sentiments) dashboard.add_panel('C', price) return dashboard
def generateBokehApp(doc): sid = str(doc.session_context.request.arguments['sid'][0].decode('utf-8')) reset_plots(sid) df = get_filtered_df(sid) class SelectedDataLink(Link): _requires_target = True class SelectedDataCallback(LinkCallback): source_model = 'selected' source_handles = ['cds'] on_source_changes = ['indices'] target_model = 'cds' source_code = "let len = {}".format(len(df.columns)) + """ let new_indices = [] for (let i = 0; i < source_selected.indices.length; i++){ let index = source_selected.indices[i] j = len-1-(index%len)+Math.floor(index/(len))*(len) new_indices[i] = j } var inds = source_selected.indices var d = source_cds.data selected_data = {} selected_data['index1'] = [] selected_data['index2'] = [] selected_data['value'] = [] selected_data['zvalues'] = [] for (var i = 0; i < inds.length; i++){ selected_data['index1'].push(d['index1'][inds[i]]) selected_data['index2'].push(d['index2'][inds[i]]) selected_data['value'].push(d['value'][inds[i]]) selected_data['zvalues'].push(d['zvalues'][inds[i]]) } target_cds.data = selected_data """ SelectedDataLink.register_callback('bokeh', SelectedDataCallback) # Set theme for holoviews plots theme = Theme( json={ 'attrs': { 'Figure': { 'background_fill_color': None, 'border_fill_color': None, 'outline_line_color': None, }, 'Grid': { 'grid_line_dash': [6, 4], 'grid_line_alpha': .3, }, 'Axis': { 'major_label_text_color': 'black', 'axis_label_text_color': 'black', 'major_tick_line_color': 'black', 'minor_tick_line_color': 'black', 'axis_line_color': "black" }, 'ColorBar': { 'background_fill_color': None, }, 'Nodes': { 'hover_fill_color': 'green', }, 'Points': { 'hover_fill_color': 'green', }, 'Graph': { 'hover_fill_color': 'green', } } }) renderer('bokeh').theme = theme renderer('bokeh').webgl = True class VisApp(Parameterized): Screen1 = ObjectSelector(default="force", objects=["none", "radial", "force", "hierarchical", "3d"]) Screen2 = ObjectSelector(default="matrix", objects=["none", "matrix"]) Ordering = ObjectSelector(default="ward", objects=["none", "single", "average", "complete", "centroid", "weighted", "median", "ward"]) Metric = ObjectSelector(default="euclidean", objects=["euclidean", "minkowski", "cityblock", "sqeuclidean", "cosine", "correlation", "hamming", "jaccard", "chebyshev", "canberra", "braycurtis"]) Color_palette = ObjectSelector(default='kbc', objects=['kbc', 'kgy', 'bgy', 'bmw', 'bmy', 'cividis', 'dimgray', 'fire', 'inferno', 'viridis']) Node_size = ObjectSelector(default='indegreesize', objects=['indegreesize', 'outdegreesize', 'totaldegreesize', 'inweightsize', 'outweightsize', 'totalweightsize']) Node_color = ObjectSelector(default='totalweight', objects=['indegree', 'outdegree', 'totaldegree', 'inweight', 'outweight', 'totalweight']) Ran = Boolean(default=False) def __init__(self, datashaded = True): self.datashaded = datashaded super(VisApp, self).__init__() @depends('Screen1', 'Screen2', 'Ordering', 'Metric', 'Color_palette', 'Node_size', 'Node_color') def view(self): if self.Screen1 == "radial": set_screen1("radial", sid) populate_radial_diagram(df, sid, datashaded=self.datashaded) if self.Screen1 == "force": set_screen1("force", sid) populate_force_diagram(df, sid, datashaded=self.datashaded) if self.Screen1 == "hierarchical": set_screen1("hierarchical", sid) populate_hierarchical_diagram(df, sid, datashaded=self.datashaded) if self.Screen1 == "3d": set_screen1("3d", sid) populate_3d_diagram(df, sid) # print(s1[1]) screen1 = get_custom_key(get_screen1(sid), sid) if self.Screen1 == "3d": zero_zero = Column(get_custom_key(get_screen1(sid), sid), css_classes=['screen-1', 'col-s-6']) else: screen1.color_palette = self.Color_palette screen1.node_size = self.Node_size screen1.node_color = self.Node_color set_custom_key(get_screen1(sid), screen1, sid) if self.Screen2 == "matrix": set_screen2("matrix", sid) populate_matrix(get_matrix_df(sid), sid) screen2 = get_custom_key(get_screen2(sid), sid) screen2.reordering = self.Ordering screen2.metric = self.Metric screen2.color_palette = self.Color_palette set_custom_key(get_screen2(sid), screen2, sid) matrix = screen2.view() edge_table = Table(matrix.data).opts(height=int(get_window_height(sid)/3), width=290) SelectedDataLink(matrix, edge_table) zero_one = Column(matrix, css_classes=['screen-2', 'col-s-6']) if self.Screen1 != "3d": # Setting up the linking, generateDiagram functions return two-tuple (graph, points). Points is the selection layer # makeMatrix returns matrix_dropdown object. matrix.view returns the heatmap object SelectMatrixToNodeLink.register_callback('bokeh', SelectMatrixToNodeCallback) SelectNodeToMatrixLink.register_callback('bokeh', SelectNodeToMatrixCallback) SelectNodeToTableLink.register_callback('bokeh', SelectNodeToTableCallback) graph, points = screen1.view() node_table = Table(points.data[['index', 'indegree', 'outdegree']]).opts(height=int(get_window_height(sid)/3), width=290) # Link matrix to the nodelink (both graph and points) SelectMatrixToNodeLink(matrix, points) SelectNodeToTableLink(points, node_table) # Link nodelink to matrix (points only) SelectNodeToMatrixLink(points, matrix) # For highlighting edges when tapping on node, but doesn't work # if not self.datashaded: # PointToGraphLink.register_callback('bokeh', PointToGraphCallback) # PointToGraphLink(points, graph) zero_zero = Column(graph * points, css_classes=['screen-1', 'col-s-6']) if not self.Ran: zero_two = Row(Column(node_table, css_classes=['node-table', 'invisible']), Column(edge_table, css_classes=['edge-table', 'invisible']), css_classes=['trash']) else: if not self.Ran: zero_two = Row(Column(edge_table, css_classes=['edge-table', 'invisible']), css_classes=['trash']) # SelectedDataLink(matrix, points) # renderer = renderer('bokeh') # print(renderer.get_plot(points).handles) if not self.Ran: self.Ran = True return Row(zero_zero, zero_one, zero_two, css_classes=['good-width']) return Row(zero_zero, zero_one, css_classes=['good-width']) visApp = VisApp(datashaded=get_datashading(sid)) set_visualisations_app(visApp, sid) extension('plotly') # Don't use pn.Pane since that messes up linking return Column(visApp.view).get_root(doc)
#imports for data proc from numpy import nan import datetime # In[ ]: from bokeh.themes.theme import Theme theme = Theme( json={ 'attrs' : { 'Figure' : { 'outline_line_width': 0, }, } }) # In[ ]: css = ''' .bk.panel-widget-box { background: #f0f0f0; border-radius: 5px; border: 1px black solid; } '''
def set_elvis_style(cls, theme='light'): hv.extension('bokeh') hv.renderer('bokeh').theme = Theme(json=cls.style(theme)) cls.curve_defaults() cls.point_defaults()
"#F53315", "#F86B32", "#F4A564", "#F0D5A8", "#6EAA9F", "#038996", "#036C8E", "#011E50" ] unit_tier_stacked_bar_color_palette = ["#036C8E", "#F4A564", "#F53315"] unit_stacked_bar_theme = Theme( json={ "attrs": { "Figure": { "background_fill_color": "#1C1A10", "background_fill_alpha": 0.85, "plot_height": 950, "plot_width": 1400 }, "Axis": { "major_label_text_font_size": "10pt", "axis_label_text_font_size": "30pt", "axis_label_text_font_style": 'bold', "axis_label_text_color": "#F8BE00", "axis_line_color": "#46433D", "axis_line_width": 3.3, "axis_line_alpha": 0.7 }, "Grid": {}, "Title": { "text_color": "#feffe1", "text_font": "times", "text_font_style": "italic" } } })
from bokeh.models import DatetimeTickFormatter from bokeh.themes.theme import Theme from random import shuffle import warnings import json import datetime as dt from lib.twitlib import twitter_premium_as_df warnings.filterwarnings('ignore') # Style with open('./theme.yaml', 'r') as infile: json_data = json.load(infile) theme_doc = Theme(json=json_data) # Load data data = twitter_premium_as_df('../data/clean/') data.data.set_index('created_at') # Make 3 DataFrames (P, N, NEU) data_P = data.loc[data['positive'] > 0.5] data_N = data.loc[data['negative'] > 0.5] data_NEU = data.loc[data['neutral'] > .05] quoted_retweet_count quoted_reply_count quoted_quote_count
location="center") p.add_layout(legend, 'right') return p from bokeh.themes.theme import Theme from bokeh.io import curdoc theme = Theme( json={ 'attrs': { 'Figure': { 'background_fill_color': 'white', 'border_fill_color': 'white', 'outline_line_color': 'white', }, 'Grid': { 'grid_line_dash': [6, 4], 'grid_line_alpha': .3, }, 'Axis': { 'major_label_text_color': 'black', 'axis_label_text_color': 'black', 'major_tick_line_color': 'black', 'minor_tick_line_color': 'black', 'axis_line_color': "white" } } }) # # how i set themes for some of the plots # curdoc().theme = theme