Hello Community ,
I am new to the community, first time actually.
Due to my lack of experience , I am unable to solve my problem which is the title of this topic.
The short version of hours of reading and sampling , I am unable to figure out the challenges posed.
I am trying to plot a simple line or bar plot to plot the change in a category value over time.
I tried using ,
p = figure(x_axis_type=‘datetime’) #set the plot x axis to read datetime format
I later went back to my data set and added a ID in sequence for each date and used
p= figure(x_range= str(ID)) # set the ID as the range for the x-axis
For both instance the same error has been returned.
So if there is any community member out there that can help me fix my problem I would be very thankful
Below is the code
from bokeh.models import Legend, LegendItem
from bokeh.plotting import figure, output_file, show
from bokeh.models import ColumnDataSource
from bokeh.models.tools import HoverTool
# Import tools for handling multiple columns
from bokeh.palettes import Spectral5
from bokeh.transform import factor_cmap
# Set-up a blank file called ADX at the folder hosting webpages for website
# read the data in the csv file in
output_file("C:/xampp/htdocs/ADX.html")
#& set the Date column to pandas datetime format
data = pd.read_csv('C:/Users/enda/Desktop/AI-Stock-Prediction-master/BTCEUR.csv',parse_dates=['Date'])
#make sure Date is a pandas datetime format
data['Date'] = pd.to_datetime(data['Date'], format='%d/%m/%Y')
#Check the Date column is pandas date format
data.tail(10)
#Create ColumnDataSource from Bokeh data frame
source = ColumnDataSource(data)
# set variable names
ID= str(data["ID"])
ADX = data["ADX"]
Open = data["Open"]
High = data["High"]
Low = data["Low"]
#convert columns to individual lists, Bokeh
ID = source.data['ID'].tolist()
ADX = source.data['ADX'].tolist()
Open = source.data['Open'].tolist()
High = source.data['High'].tolist()
Low = source.data['Low'].tolist()
#set the plot x axis to read datetime format
p = figure(x_axis_type='datetime')
# set the Date as the range for the x-axis
p= figure(x_range= str(ID))
p.line(x='ID', y='ADX', line_width=2, source=source, legend_label='Measured ADX')
color_map = factor_cmap(field_name='ADX',
palette=Spectral5, factors= str(ID))
The error code returned is
ValueError Traceback (most recent call last)
in
52
53
—> 54 color_map = factor_cmap(field_name=‘ADX’,
55 palette=Spectral5, factors= str(ID))
56
C:\ProgramData\Anaconda3\lib\site-packages\bokeh\transform.py in factor_cmap(field_name, palette, factors, start, end, nan_color)
119
120 ‘’’
→ 121 return field(field_name, CategoricalColorMapper(palette=palette,
122 factors=factors,
123 start=start,
C:\ProgramData\Anaconda3\lib\site-packages\bokeh\models\mappers.py in init(self, **kwargs)
139
140 def init(self, **kwargs):
→ 141 super().init(**kwargs)
142 palette = self.palette
143 factors = self.factors
C:\ProgramData\Anaconda3\lib\site-packages\bokeh\models\mappers.py in init(self, palette, **kwargs)
89 if palette is not None:
90 kwargs[‘palette’] = palette
—> 91 super().init(**kwargs)
92
93 @abstract
C:\ProgramData\Anaconda3\lib\site-packages\bokeh\model.py in init(self, **kwargs)
232 kwargs.pop(“id”, None)
233
→ 234 super().init(**kwargs)
235 default_theme.apply_to_model(self)
236
C:\ProgramData\Anaconda3\lib\site-packages\bokeh\core\has_props.py in init(self, **properties)
245
246 for name, value in properties.items():
→ 247 setattr(self, name, value)
248
249 def setattr(self, name, value):
C:\ProgramData\Anaconda3\lib\site-packages\bokeh\core\has_props.py in setattr(self, name, value)
272
273 if name in props or (descriptor is not None and descriptor.fset is not None):
→ 274 super().setattr(name, value)
275 else:
276 matches, text = difflib.get_close_matches(name.lower(), props), “similar”
C:\ProgramData\Anaconda3\lib\site-packages\bokeh\core\property\descriptors.py in set(self, obj, value, setter)
537 raise RuntimeError("%s.%s is a readonly property" % (obj.class.name, self.name))
538
→ 539 self._internal_set(obj, value, setter=setter)
540
541 def delete(self, obj):
C:\ProgramData\Anaconda3\lib\site-packages\bokeh\core\property\descriptors.py in _internal_set(self, obj, value, hint, setter)
758
759 ‘’’
→ 760 value = self.property.prepare_value(obj, self.name, value)
761
762 old = self.get(obj, obj.class)
C:\ProgramData\Anaconda3\lib\site-packages\bokeh\core\property\bases.py in prepare_value(self, obj_or_cls, name, value)
329 break
330 else:
→ 331 raise e
332 else:
333 value = self.transform(value)
C:\ProgramData\Anaconda3\lib\site-packages\bokeh\core\property\bases.py in prepare_value(self, obj_or_cls, name, value)
322 try:
323 if validation_on():
→ 324 self.validate(value)
325 except ValueError as e:
326 for tp, converter in self.alternatives:
C:\ProgramData\Anaconda3\lib\site-packages\bokeh\core\property\either.py in validate(self, value, detail)
107 if not (value is None or any(param.is_valid(value) for param in self.type_params)):
108 msg = “” if not detail else “expected an element of either %s, got %r” % (nice_join(self.type_params), value)
→ 109 raise ValueError(msg)
110
111 # TODO (bev) implement this
ValueError: expected an element of either Seq(String), Seq(Tuple(String, String)) or Seq(Tuple(String, String, String)), got ‘[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, …558, 559, 560, 561]’