Transformations VII

from lesson 03_Data_ Sources_&_Transformations

And now, we have fallen off the cliff:

# Exercise: use the corresponding factor_cmap to color map a scatter plot of the iris data set


from bokeh.palettes import Viridis256
from bokeh.sampledata.iris import flowers
from bokeh.transform import factor_cmap

p = figure(title="Factor Color Map")

p.scatter(flowers['petal_width'], flowers['petal_length'], color=factor_cmap(flowers['species'], Viridis256. factors == flowers['species']))

show(p)

First:

TypeError: factor_cmap() missing 1 required positional argument: ‘factors’

And then:

AttributeError: ‘tuple’ object has no attribute ‘factors’

Given the failure of the preceding exercise with log_cmap, the failure here is not the least bit surprising to me, since this is very nearly the identical issue I came to the forum about the first time. I don’t get it. Please explain it to me like I was 5 years old.

You have used == (equality test) instead of = (assignment)

  Input In [1]
    p.scatter(flowers['petal_width'], flowers['petal_length'], color=factor_cmap(flowers['species'], Viridis256. factors = flowers['species']))
                                                                                                     ^
SyntaxError: expression cannot contain assignment, perhaps you meant "=="?

In Python, parameters passed to functions are separated by commas. You have a period (.) after Viridis256 instead of a comma (,) Just to be clear, any time there is a SyntaxError that means you have written invalid Python code.

@malikarumi I don’t mean this disrespectfully. No one is innately endowed with Python knowledge, it’s something we all have to start from the beginning, and learn over time. I do think that your attempt to learn Bokeh is currently hampered by a lack of basic knowledge of Python in general, and I would advise that you take a step back and look into some basic Python tutorials first, before attempting to dive into a large and complicated library like Bokeh. This forum is for specialized support that benefits from deep Bokeh expertise. It not the appropriate place to seek basic Python programming help.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.