0

How do I change text alignment inside a bokeh Div widget? I want it to be aligned in the 'centre'.

show(column(Div(text='<p style="text-align: center;"><center><h1>Figure 1<h1><center></p>',  style={'font-size': '150%'}), gridplot))

As you can see, I've tried some HTML edits above (among others) but nothing works. I don't code in HTML so I have no idea how to make it work. Any help would be very appreciated!

A bit of background: I'm trying to make an overarching title for the gridplot (bokeh doesn't have this functionality)

Drishti
  • 33
  • 2
  • 6

1 Answers1

-1

Bokeh allows CSS to center headers, paragraphs, and sections:

text = """
<html>
<head>
<style>
h1 {text-align: center;}
p {text-align: center;}
div {text-align: center;}
</style>
</head>
<body>

<h1>This is a heading</h1>
<p>This is a paragraph.</p>
<div>This is a div.</div>

</body>
</html>
"""


show(Div(text=text))

This will result in the following:

enter image description here

Note that this will be centered with regard to the width of the Div class, which has a default of 200. You can change this by passing width as an argument:

show(Div(text=text, width=500))
Nick Morgan
  • 415
  • 5
  • 17