0

In Jupyter Notebooks I read in a dataframe and create several plots with Pandas / Bokeh. While creating one of the latter I get an error. Search for similar problems said, that there might be somewhere above in the script something like

plt.title = "Title"

which overwrites the method. But this is not the case for me. I have nothing similar in the code above -exept in the figure parameters. Here the Bokeh documentation describes to set a figure title like I used it.

Using the part of the code that leads the the error in the complete notebook in a stand-alone script only does NOT lead to the error. So, also in my case the problem might have something to do with my code above. But maybe some of you has an idea when seeing this..(?)

import pandas as pd
import numpy as np

import matplotlib.pyplot as plt

from bokeh.plotting import figure, show, output_notebook, ColumnDataSource
from bokeh.io import output_notebook
from bokeh.layouts import column, gridplot
from bokeh.models import Label, Title
from bokeh.models import Div

data = df
output_notebook()

# Title of the overall plot
abovetitle = ("This should be the overall title of all graphs")
               
# GRAPH 1
s1 = figure(width = 250, plot_height = 250, title="Graph 1", x_axis_label = "axis title 1", y_axis_label = 'µs')
s1.line(x, y, width=1, color="black", alpha=1, source = data)
# s1.title.text = "Title With Options" # this is a instead-off 'title=' test, but does not solve the problem

# GRAPH 2
s2 = figure(width = 250, plot_height = 250, title="Graph 2", x_axis_label = "axis title 2, y_axis_label = 'µs')
s2.line(x, y, width=1, color="blue", alpha=1, source = data)
#s2.title.text = "Title With Options" # this is a instead-off 'title=' test, but does not solve the problem

# plot graphs:
p = gridplot([[s1, s2]])  
show(column(Div(text=abovetitle), p))

leads to the type error

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-24-33e4828b986d> in <module>
     31 # plot graphs:
     32 p = gridplot([[s1, s2]])
---> 33 show(column(Div(text=title), p))

TypeError: 'str' object is not callable

Recalling

import matplotlib.pyplot as plt

does not solve the problem. Hence, recalling

import pandas as pd
import numpy as np

import matplotlib.pyplot as plt

from bokeh.plotting import figure, show, output_notebook, ColumnDataSource
from bokeh.io import output_notebook
from bokeh.layouts import column, gridplot
from bokeh.models import Label, Title
from bokeh.models import Div

solves the problem. Any further idea what might cause this error?

In the mean time I got a very useful hint: In one of the prior cells I accidentially used a Bokeh API function name as variable name and overwrote the function. If someone faces a comparable problem have a look at your variable naming. Maybe there happend the same accident... ;-)

#############################
# Define column names of XData binary part
header = ["Col1","Col2","Col3"] 

# Split XData in single, space separated columns 
x_df = selected_df.XData.str.split(' ', expand=True)
x_df.drop(0, inplace=True, axis=1)
x_df.columns = header
#print(x_df)

# Binary XData to integer
for column in x_df:         # DONT DO THAT!!!!! THIS OVERWRITES BOKEH API FUNCTION. EG. USE `col` INSTEAD OF `column`
    x_df[column] = x_df[column].apply(int, base=16)     # DONT DO THAT!!!!! THIS OVERWRITES BOKEH API FUNCTION. EG. USE `col` INSTEAD OF `column`
Swawa
  • 143
  • 1
  • 9
  • You're importing `output_notebook` twice - once from `bokeh.plotting` and once from `bokeh.io`. – MattDMo Jul 14 '22 at 16:19
  • 1
    That is irrelevant, the `bokeh.plotting` version is the same as the `bokeh.io` version. @swana I tried investigating your code but it is missing data, and has syntax error. I will happily try to help if you can provide a complete [Minimal Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) that can actually be run. Otherwise, all I can note is that the error means that you have assigned one of the names `show`, `column`, or `Div` to be a string value (overwriting the Bokeh API functions, which is bad). Examine their values to see which and don't let that happen – bigreddot Jul 15 '22 at 04:10
  • @bigreddot Thanks for your deep look. That is a little bit confusing as this is the first graph that is produced in the script. I have some `column` containing code above. Which is intended to only make some calculations and not overwrite methods or functions... in the mean time I try to create a minimum reproducible with data. give me a little time – Swawa Jul 15 '22 at 04:47
  • @bigreddot I meant I could reproduce the error in a very reduced code where it is the very first plot to be created. I think your hint might be a spoor to a miscoding. At the moment I am failing in producing a minimum dataset... as these are several .xml-file to be merged in to one big dataframe... Let me try if renaming of my `column` in the prior code does help (I added it in my post, but I am afraid this is not a big help as its just another snipped without data :-(.... – Swawa Jul 15 '22 at 05:08
  • @bigreddot That was it! WOW, thanks a lot for your uncredible got hint! I used `column` in the above code as variable name and overwrote the Bokeh API function. Replacing my variable to `col` makes the notebook go again. I voted for your comment. YOU ARE GREAT :-)))))) – Swawa Jul 15 '22 at 05:16

0 Answers0