In [96]:
from bokeh.plotting import figure
from bokeh.io import output_file, show, output_notebook
from bokeh.models import Range1d, PanTool, ResetTool, HoverTool
In [72]:
iris = pd.read_csv("iris.csv")
In [73]:
iris.head()
Out[73]:
In [74]:
#output_file("scatter.html")
In [97]:
f = figure(tools = [PanTool(), ResetTool(), HoverTool()])
In [76]:
dir(f)
Out[76]:
In [98]:
output_notebook()
In [99]:
colormap = {'Iris-setosa': 'red', 'Iris-versicolor': 'green', 'Iris-virginica': 'blue'}
colors = [colormap[x] for x in iris['Species']]
In [10]:
f.circle(iris.PetalLengthCm, iris.PetalWidthCm, size= 10, fill_alpha = 0.2, color = colors)
Out[10]:
change width, height, and background color¶
In [100]:
f.plot_height = 400
f.plot_width = 600
f.background_fill_color = "grey"
f.background_fill_alpha = 0.4
In [12]:
show(f)
Add title¶
In [101]:
f.title.text = "Iris Bokeh Demo"
f.title.text_color = "red"
f.title.text_font = "times"
f.title.text_font_size = "44px"
Axes Styling¶
In [102]:
f.axis.minor_tick_line_color = "red"
f.axis.major_tick_line_color = "blue"
f.xaxis.axis_label = "Petel Length"
f.yaxis.axis_label = "Petal Width"
In [15]:
show(f)
Axis geometry¶
In [16]:
f.x_range = Range1d(start = 0, end = 10)
f.y_range = Range1d(start = 0, end = 5)
In [17]:
show(f)
Style the tools¶
In [103]:
f.toolbar.logo = None
In [19]:
show(f)
In [104]:
iris["colors"] = colors
In [84]:
f.circle(iris.PetalLengthCm, iris.PetalWidthCm, fill_alpha = 0.2, color = colors, size = iris.SepalWidthCm*4)
Out[84]:
In [85]:
show(f)
Add legend¶
In [105]:
iris.head()
Out[105]:
In [106]:
for spec in iris.Species.unique():
f.circle(iris[iris["Species"] == spec].PetalLengthCm, iris[iris["Species"] == spec].PetalWidthCm, fill_alpha = 0.2, color = iris[iris["Species"] == spec].colors, size = iris[iris["Species"] == spec].SepalWidthCm*4, legend = spec)
In [107]:
show(f)
style the legend¶
In [108]:
f.legend.location = "top_left"
In [109]:
show(f)
In [ ]:
No comments :
Post a Comment