def scatter(): scatter = vincent.Scatter(data.multi_iter2, width=WIDTH, height=HEIGHT, iter_idx='index') scatter.axis_titles(x='Index', y='Data Value') scatter.legend(title='Categories') return scatter.to_json()
def test_datetimeandserial(self): '''Test pandas serialization and datetime parsing''' rng = pd.date_range('1/1/2013', periods=30, freq='D') ts = pd.Series(np.random.randn(len(rng)), index=rng) scatter = vincent.Scatter() scatter.tabular_data(ts) timevalue = time.mktime(ts.index[0].timetuple()) * 1000 assert scatter.data[0]['values'][0]['x'] == timevalue
def add_air_station_marker_with_graph(self, data, *args, **kwargs): """Esta función se encarga de agregar graficos al los marcadores existentes""" locations = data.iloc[:, [1, 2]] station_names = data.iloc[:, [3]] station_ids = list(pd.unique(data.id)) station_groups = data.groupby('id') for station_id in station_ids: filtered_data = station_groups.get_group(station_id) print('***** data get group') print(type(filtered_data)) print(filtered_data.head()) plot_data = filtered_data.groupby( ['magnitude', 'year', 'month', 'day']).agg({ 'value': 'mean' }).reset_index() print('***** data plot data') print(type(plot_data)) print(plot_data.head()) x = [int(hour) for hour in list(plot_data['day'])] y = [int(value) for value in list(plot_data['value'])] print(x) print(y) xy_values = { 'x': x, 'y': y, } scatter_chart = vincent.Scatter(xy_values, iter_idx='x', width=600, height=300) scatter_chart.axis_titles(x='Día', y='Promedio Dióxido de Nitrogeno día') popup_scatter_plot = folium.Popup(max_width=900).add_child( folium.Vega(scatter_chart, height=350, width=700)) air_quality_station = [ filtered_data.iloc[0, 1], filtered_data.iloc[0, 2] ] print(air_quality_station) station_name = [filtered_data.iloc[0, 3]] print(station_name) folium.Marker( location=air_quality_station, tooltip=folium.Tooltip( f'Estación: {station_name[0]}<br>Latitud: {round(air_quality_station[0], 4)}<br>Longitud: {round(air_quality_station[1], 4)}' ), popup=popup_scatter_plot, icon=folium.CustomIcon(icon_image='icons/forecast.png', icon_size=(40, 40))).add_to(self._map)
def draw_markers(self, data, coordinates, style, label, mplobj=None): import vincent # only import if VincentRenderer is used if coordinates != 'data': warnings.warn("Only data coordinates supported. Skipping this") markerdata = {'x': data[:, 0], 'y': data[:, 1]} markers = vincent.Scatter(markerdata, iter_idx='x', width=self.figwidth, height=self.figheight) # TODO: respect the other style settings markers.scales['color'].range = [style['facecolor']] if self.chart is None: self.chart = markers else: warnings.warn("Multiple plot elements not yet supported")
def plotrwresult(G): visits = [G.node[node]['visits'] for node in G.nodes_iter()] norm_visits = np.array(visits) / float(G.graph['total_visits']) deaths = [G.node[node]['deaths'] for node in G.nodes_iter()] norm_deaths = np.array(deaths) / float(sum(deaths)) if G.is_directed(): degrees = [G.in_degree(node) for node in G.nodes_iter()] norm_degrees = np.array(degrees) / float(G.size()) else: degrees = [G.degree(node) for node in G.nodes_iter()] aorm_degrees = np.array(degrees) / float(2 * G.size()) multi_iter1 = { 'index': range(G.order()), 'Visits': norm_visits, 'Deaths': norm_deaths, 'Degree': norm_degrees } line = vincent.Scatter(multi_iter1, iter_idx='index') line.axis_titles(x='Vertex', y='Juice') line.legend(title='Results') line.width = 400 line.height = 300 line.marks[0].marks[0].properties.enter.opacity = vincent.ValueRef(value=1) line.marks[0].marks[0].properties.update = vincent.PropertySet() line.marks[0].marks[0].properties.update.size = vincent.ValueRef(value=100) line.marks[0].marks[0].properties.hover = vincent.PropertySet() line.marks[0].marks[0].properties.hover.size = vincent.ValueRef(value=200) line.marks[0].marks[0].properties.update.size = vincent.ValueRef(value=100) line.marks[0].marks[0].properties.hover = vincent.PropertySet() line.marks[0].marks[0].properties.hover.size = vincent.ValueRef(value=200) line.scales['shape'] = vincent.Scale( name='shape', type='ordinal', domain=vincent.DataRef(data='table', field='data.col'), range=["square", "circle", "triangle-down", "triangle-up"]) line.marks[0].marks[0].properties.enter.shape = vincent.ValueRef( scale="shape", field="data.col") line.legends[0].shape = "shape" return line
def test_datetimeandserial(self): '''Test pandas serialization and datetime parsing''' import pandas.io.data as web all_data = {} for ticker in ['AAPL', 'GOOG']: all_data[ticker] = web.get_data_yahoo(ticker, '1/1/2004', '1/1/2006') price = pd.DataFrame( {tic: data['Adj Close'] for tic, data in all_data.iteritems()}) scatter = vincent.Scatter() scatter.tabular_data(price, columns=['AAPL', 'GOOG']) assert scatter.data[0]['values'][0]['x'] == 10.49 nt.assert_is_none(scatter.data[0]['values'][0]['y']) line = vincent.Line() line.tabular_data(price, columns=['AAPL']) assert line.data[0]['values'][0]['x'] == 1073030400000
line = vincent.Line(multi_iter1, iter_idx='index') line.axis_titles(x='Index', y='Value') line.legend(title='Categories') line.display() # <codecell> line = vincent.Line(price[['GOOG', 'AAPL']]) line.axis_titles(x='Date', y='Price') line.legend(title='GOOG vs AAPL') line.display() # <codecell> scatter = vincent.Scatter(df_1) scatter.axis_titles(x='Index', y='Data Value') scatter.legend(title='Categories') scatter.colors(brew='Set3') scatter.display() # <codecell> stacked = vincent.StackedArea(df_1) stacked.axis_titles(x='Index', y='Value') stacked.legend(title='Categories') stacked.colors(brew='Spectral') stacked.display() # <codecell>
# -*- coding: utf-8 -*- ''' Builds a Vega grammar specification from vincent.Scatter() ''' import vincent import random vis = vincent.Scatter() vis.tabular_data([random.randint(10, 100) for x in range(0, 201, 1)]) #Generate both the Vega JSON and a data JSON. path = r'/vega.json' vis.to_json(path, split_data=True, html=True) #Make the visualization wider, and add a hover to the points vis.update_vis(width=800) vis + ({ 'fill': { 'value': '#2a3140' }, 'size': { 'value': '100' } }, 'marks', 0, 'properties', 'update') vis + ({ 'fill': { 'value': '#a63737'
m.save(os.path.join('recursos', 'dibujar.html')) ####################################### import json import numpy as np import vincent N = 100 multi_iter2 = { 'x': [4, 5, 6], 'y': [1, 2, 3], } scatter = vincent.Scatter(multi_iter2, iter_idx='x', height=100, width=200) data = json.loads(scatter.to_json()) m = folium.Map([-34.969672, -71.230373], zoom_start=12) mk = features.Marker([-34.969672, -71.230373]) p = folium.Popup('Hello') v = features.Vega(data, width='100%', height='100%') mk.add_child(p) p.add_child(v) m.add_child(mk) m.save(os.path.join('recursos', 'mapaGrafico.html')) #################################
import json import numpy as np import folium from folium import Vega import vincent scatter_points = { 'x': np.random.uniform(size=(100, )), 'y': np.random.uniform(size=(100, )), } # Let's create the vincent chart. scatter_chart = vincent.Scatter(scatter_points, iter_idx='x', width=600, height=300) # Let's convert it to JSON. scatter_json = scatter_chart.to_json() # Let's convert it to dict. scatter_dict = json.loads(scatter_json) m = folium.Map([43, -100], zoom_start=4) popup = folium.Popup() folium.Vega(scatter_chart, height=350, width=650).add_to(popup) folium.Marker([30, -120], popup=popup).add_to(m) # Let's create a Vega popup based on scatter_json.