# we fill a df with the data of interest and create a groupby pandas object df = flowers[["petal_length", "petal_width", "species"]] xyvalues = g = df.groupby("species") # here we only drop that groupby object into a dict .. pdict = OrderedDict() for i in g.groups.keys(): labels = g.get_group(i).columns xname = labels[0] yname = labels[1] x = getattr(g.get_group(i), xname) y = getattr(g.get_group(i), yname) pdict[i] = zip(x, y) # any of the following commented are valid Scatter inputs #xyvalues = pdict #xyvalues = pd.DataFrame(xyvalues) #xyvalues = xyvalues.values() #xyvalues = np.array(xyvalues.values()) TOOLS = "resize,crosshair,pan,wheel_zoom,box_zoom,reset,previewsave" scatter = Scatter(xyvalues, filename="iris_scatter.html", tools=TOOLS, ylabel='petal_width', facet=False) scatter.title("iris dataset").legend("top_left") scatter.width(600).height(400).show()
# Testing random data df = pandas.DataFrame(columns=['X', 'Y']) df['X'] = [1, 2, 3, 4, 5] df['Y'] = [6, 7, 8, 9, 10] p = Scatter(df, x='X', y='Y', title="Temperature Observation", xlabel='Days of observations', ylabel='Temperature') output_file('Scatter_charts.html') # Generate an HTML file # show(p) # Show # ----- (2) Test using bokeh.plotting (recommended for more customization) ----- # p = figure(plot_width=500, plot_height=400, title='Earthquake') p = figure(plot_width=500, plot_height=400) # help(p) p.title = 'Earthquake' p.title_text_color = 'Orange' p.title_text_font = 'Times' p.title_text_font_style = 'italic' p.yaxis.minor_tick_line_color = None p.xaxis.axis_label = 'Times' p.yaxis.axis_label = 'Value' # quad may also be used p.circle([4, 8, 12], [7, 14, 21], size=17, color='orange', alpha=0.5) # p.triangle(df['X'], df['Y'], size=10, color='red', alpha=0.5) p.triangle(df['X'], df['Y'], size=[5, 10, 15, 20, 25], color='red', alpha=0.5) output_file('Scatter_plotting.html') # show(p) # ----- (3) Exercise: Reading from excel -----
from bokeh.charts import Scatter # we fill a df with the data of interest and create a groupby pandas object df = flowers[["petal_length", "petal_width", "species"]] xyvalues = g = df.groupby("species") # here we only drop that groupby object into a dict .. pdict = OrderedDict() for i in g.groups.keys(): labels = g.get_group(i).columns xname = labels[0] yname = labels[1] x = getattr(g.get_group(i), xname) y = getattr(g.get_group(i), yname) pdict[i] = zip(x, y) # any of the following commented are valid Scatter inputs #xyvalues = pdict #xyvalues = pd.DataFrame(xyvalues) #xyvalues = xyvalues.values() #xyvalues = np.array(xyvalues.values()) TOOLS="resize,crosshair,pan,wheel_zoom,box_zoom,reset,previewsave" scatter = Scatter( xyvalues, filename="iris_scatter.html", tools=TOOLS, ylabel='petal_width', facet=False ) scatter.title("iris dataset").legend("top_left") scatter.width(600).height(400).show()
from bokeh.sampledata.iris import flowers # we fill a df with the data of interest and create a groupby pandas object df = flowers[["petal_length", "petal_width", "species"]] g = df.groupby("species") # here we only drop that groupby object into our Scatter chart from bokeh.charts import Scatter scatter = Scatter(g, filename="iris_scatter.html") scatter.title("iris dataset, gp_by_input").legend("top_left").width(600).height(400).show()