I would like to automatically adjust the width of a bokeh DataTable to the size of a screen. But I do not find the right way to do it. This line of code is supposed to work :
data_table = DataTable(source=source, columns=columns, height = 300, sizing_mode = 'scale_width', fit_columns=True)
But it does not. My Datatable keeps the same width.
Does anyone know how to solve this problem ?
Thank you.
I'm afraid it's not possible with the current implementation of DataTable - if you don't specify an explicit width in pixels, the width will be set to 600px.
You're welcome to create a feature request on Bokeh's GitHub.
As of 2.2.3 and likely earlier you can use sizing_mode:
import pandas as pd, numpy as np, random, string
from bokeh.models import ColumnDataSource, DataTable, TableColumn
from bokeh.plotting import show
df = pd.DataFrame(np.random.randint(0,100,size=(100, 12)), columns=[(random.randint(1,30) * random.choice(string.ascii_uppercase)) for col in range(12)])
data_table = DataTable(columns = [TableColumn(field=c, title=c) for c in df.columns], sizing_mode='stretch_width', source = ColumnDataSource(df))
show(data_table)
Related
lm = sns.lmplot(x='early_mean_zscores', y='late_mean_zscores', col='cat', data=combo)
fig = lm.fig
fig.suptitle("Improvement from Early to Late assignments")
a1 = fig.axes[1]
a1.title("adsadas")
I would like to set the title of the subplots generated by hand, i.e. not based on the col='cat'. This code, and many permutations of it that I have tried don't seem to work.
I don't understand the timing of when the plot is fixed and displayed. Is it on the first line, lm = ... in which case it's not surprising that I cannot, retroactively change the title.
I could use some help on both fixing the code, and a clarification on the sequencing and theory of what is going wrong.
The command to set a title is ax.set_title(). Using that, the code should work as expected.
A minimal example:
import matplotlib.pyplot as plt
import seaborn as sns
tips = sns.load_dataset("tips")
lm = sns.lmplot(x="total_bill", y="tip", col="smoker", data=tips)
fig = lm.fig
fig.suptitle("Custom Super Title")
a1 = fig.axes[1]
a1.set_title("Custom Title")
plt.show()
depending on what you need, you could just use:
lm = sns.lmplot(x="total_bill", y="tip", col="smoker", data=tips).set_titles("{col_name}") # {col_name} is special parameter of actual column name
Case: multi-line by \n.
I think the same modification to bokeh text required.
from bokeh.io import output_file, show
from bokeh.models import Label
from bokeh.plotting import figure
output_file("text.html")
p = figure(x_range=(0, 5))
p.text(x=[1,2,3], y = [0,0,0], text=['hello\nworld!', 'hello\nworld!', 'hello\nworld!'], angle = 0)
label = Label(x=2, y=-0.5,
text='label\nworld',render_mode='css',border_line_alpha=0.5,
background_fill_alpha=0.5)
p.add_layout(label)
show(p)
enter image description here
As of version 0.12.13 multi line text is only supported by the text glyph. If you'd like to request it be added to Label please make a feature request issue on GitHub.
I have a tkinter interface with a few entry widgets as inputs. Upon clicking a button I would like those inputs to be sent to a separate script to be processed and a value printed and potentially returned back to the button (I am looking at this for a dual accuracy assessment statistic)
This is a lower scale example of what I have so far and am looking to accomplish
Example Secondary Script: GUI_ConnectorScript
def calculate():
global result
result = int(entry.get())
result += 1
print result
Primary Script: GUI_ConnectorScript
from Tkinter import *
import GUI_ConnectorScript
background = "#A8A8A8"
master = Tk()
screen_width = master.winfo_screenwidth()
screen_height = master.winfo_screenheight()
width = int(screen_width*0.7)
height = int(screen_height*0.7)
size = "%sx%s"%(width,height)
master.geometry(size)
master.title("GIS Display")
text = Text(master, width = 80, height = 40, background = background)
text.pack(expand = TRUE, fill = BOTH)
entry = Entry(master, width=5).place(x=100,y=100)
button = Button(master, text="Calculate", command=GUI_ConnectorScript).place(x=500,y=500)
mainloop()
I have been trying to figure this out for awhile and have look around a lot for an answer. I have found examples similar but I am having an issue getting it to work for my application.
I agree with Parviz, whenever GUI programs get too complicated you should use Object-Oriented Programming.
I can further advice that you use kivy (if possible) instead of tkinter, its much better for bigger projects
Here is my code:
from tkinter import *
import textwrap
GUI = Tk()
note_frame = Frame(GUI)
note_frame.grid(row=0, column=0)
note_scrollbar = Scrollbar(note_frame)
note_scrollbar.pack(side=RIGHT, fill=Y)
note_container = Canvas(note_frame, yscrollcommand = note_scrollbar.set)
note_container.pack()
note_scrollbar.config(command=note_container.yview)
def configure_note_container(event):
note_container.config(scrollregion=note_container.bbox("all"),
width=200, height=200)
note_list = Frame(note_container, width=200, height=200)
note_container.create_window((0,0), window=note_list, anchor='nw')
note_list.bind("<Configure>", configure_note_container)
for x in range(100):
exec(textwrap.dedent(
"""
label_{0} = Label(note_list, text='{0}', bg="white")
label_{0}.grid(column=0, row={0})
""".format(x)))
GUI.mainloop()
I am trying to get the labels to stretch out to fill the X width of the grid cell within the frame (which is within a canvas so that I can use a scrollbar), but I don't know how to do it - when the note_container gets configured, it seems to cancel out any adjustment of size. grid_propagate doesn't seem to work either.
Any help is appreciated. thanks.
I'm working with Bokeh and I want to add a circle on a specific position on my image.
For the moment, I create my image like this :
img = image(image=[data],
x_range=[0, x_range],
y_range=[0, y_range],
x=x,
y=y,
dw=dw,
dh=dh,
tools=TOOLS,
palette=["Greys-9"],
title=title,
plot_width=plot_width,
plot_height=plot_height,
)
circle(x=10,y=10,radius=100,fill_color="#df1c1c",line_color="#df1c1c")
resources = Resources("inline")
plot_script, plot_div = components(img, resources)
html_script = encode_utf8(plot_script)
html_div = encode_utf8(plot_div)
hold()
figure()
return html_script, html_div
and send this to my HTML page.
The problem is that the circle is not on the final display. Maybe on background ? I don't know...
I tryed add function, add_glyph function, add_layout... None of these are functionnal!
Thanks for helping guys
The above code did not work due to a bug in Bokeh. However, the bug has since been fixed, and that code and code similar to it will function as expected.