vladimirov1
vladimirov1
vladimirov1 @ Snip2Code
3 Snippets  (197th place)
Published
1 Channel
Created
4 Channels
Following
Jun 3, 2017
Last Visit
Jun 3, 2017
Registered
3 points  (13108th place)
Reputation
Junior Code Generator
Junior Popular Coder
Junior Autobiographer
Senior Autobiographer

Recent Snippets See all snippets by vladimirov1

public by vladimirov1 created May 18, 2017  79  0  1  0

print crosfilter results in console

print crosfilter results in console: print_filter.js
/**
 * Created by user on 18/05/17.
 */
			// Super useful for debug in web console
			function print_filter(filter){
				var f=eval(filter);
				if (typeof(f.length) != "undefined") {}else{}
				if (typeof(f.top) != "undefined") {f=f.top(Infinity);}else{}
				if (typeof(f.dimension) != "undefined") {f=f.dimension(function(d) { return "";}).top(Infinity);}else{}
				console.log("DC DEBUG: "+filter+"("+f.length+") = "+JSON.stringify(f).replace("[","[\n\t").replace(/}\,/g,"},\n\t").replace("]","\n]"));
			}

;

public by vladimirov1 created Aug 21, 2016  112  0  2  0

From http://web.stanford.edu/~mwaskom/software/seaborn/examples/many_facets.html

From http://web.stanford.edu/~mwaskom/software/seaborn/examples/many_facets.html: Seaborn example.py
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="ticks")

# Create a dataset with many short random walks
rs = np.random.RandomState(4)
pos = rs.randint(-1, 2, (20, 5)).cumsum(axis=1)
pos -= pos[:, 0, np.newaxis]
step = np.tile(range(5), 20)
walk = np.repeat(range(20), 5)
df = pd.DataFrame(np.c_[pos.flat, step, walk],
                  columns=["position", "step", "walk"])

# Initialize a grid of plots with an Axes for each walk
grid = sns.FacetGrid(df, col="walk", hue="walk", col_wrap=5, size=1.5)

# Draw a horizontal line to show the starting point
grid.map(plt.axhline, y=0, ls=":", c=".5")

# Draw a line plot to show the trajectory of each random walk
grid.map(plt.plot, "step", "position", marker="o", ms=4)

# Adjust the tick positions and labels
grid.set(xticks=np.arange(5), yticks=[-3, 3],
         xlim=(-.5, 4.5), ylim=(-3.5, 3.5))

# Adjust the arrangement of the plots
grid.fig.tight_layout(w_pad=1)


;

public by vladimirov1 created Aug 20, 2016  40  1  1  0

From http://flexx.readthedocs.io/en/v0.2/examples/ui/with_bokeh.py.html

From http://flexx.readthedocs.io/en/v0.2/examples/ui/with_bokeh.py.html: Flexx Bokeh.py
"""
Example demonstrating a Bokeh plot in Flexx, using a Phosphor dock panel
layout. Includes client-side interaction with sliders.
"""

import numpy as np

from bokeh.plotting import figure

from flexx import app, ui, react

src = 'https://github.com/zoofIO/flexx/blob/master/examples/ui/with_bokeh.py'

# Plot 1
N = 1000
x = np.random.normal(0, np.pi, N)
y = np.sin(x) + np.random.normal(0, 0.2, N)
TOOLS = "pan,wheel_zoom,box_zoom,reset,box_select"
p1 = figure(tools=TOOLS)
p1.scatter(x, y, alpha=0.1, nonselection_alpha=0.1)

# Plot2
t = np.linspace(0, 6.5, 100)
p2 = figure(tools=TOOLS)
p2.line(t, np.sin(t))
p3 = figure(tools=TOOLS)
p3.line(t, np.cos(t))

class Example(ui.Widget):

    def init(self):

        with ui.DockPanel():
            self.plot1 = ui.BokehWidget(plot=p1, title='Scatter')
            with ui.VBox(title='Sine'):
                with ui.FormLayout():
                    self.amp = ui.Slider(title='Amplitude', max=2, value=1)
                    self.freq = ui.Slider(title='Frequency', max=10, value=5)
                    self.phase = ui.Slider(title='Phase', max=3, value=1)
                with ui.Widget(style='overflow-y:auto;', flex=1):
                    self.plot2 = ui.BokehWidget(plot=p2)
                    self.plot3 = ui.BokehWidget(plot=p3)
            # Add some colorful panels just for fun
            ui.Label(title='Info', text='Source is <a href="%s">%s</a>' % (src, src))
            ui.Widget(style='background:#0a0;', title='green')
            ui.Widget(style='background:#00a;', title='blue')

    class JS:

        @react.connect('amp.value', 'freq.value', 'phase.value')
        def _update_sine(self, amp, freq, phase):
            # Get reference to line glyph, can this be done easier?
            glyph = None
            plot = self.plot2.plot()
            if plot:
                for ren in plot.renderers.values():
                    if ren.glyph:
                        glyph = ren.glyph
                        break
            # Update
            if glyph:
                glyph.y = [amp*Math.sin(x*freq+phase) for x in glyph.x]  # noqa
                plot.render()


if __name__ == '__main__':
    m = app.launch(Example)
    app.run()


;