def plot_axis_lines(self, ax, X, color=Tango.colorsHex['mediumBlue'], label=None, marker_kwargs=None, **kwargs): if X.shape[1] == 1: annotations = Annotations() for i, row in enumerate(X): annotations.append( Annotation( text='', x=row[0], y=0, yref='paper', ax=0, ay=20, arrowhead=2, arrowsize=1, arrowwidth=2, arrowcolor=color, showarrow=True, #showlegend=i==0, #label=label, )) return annotations elif X.shape[1] == 2: marker_kwargs.setdefault('symbol', 'diamond') opacity = kwargs.pop('opacity', .8) return Scatter3d(x=X[:, 0], y=X[:, 1], z=np.zeros(X.shape[0]), mode='markers', projection=dict(z=dict(show=True, opacity=opacity)), marker=Marker(color=color, **marker_kwargs or {}), opacity=0, name=label, showlegend=label is not None, **kwargs)
def annotation_heatmap(self, ax, X, annotation, extent=None, label='Gradient', imshow_kwargs=None, **annotation_kwargs): imshow_kwargs.setdefault('label', label) imshow_kwargs.setdefault('showscale', True) imshow = self.imshow(ax, X, extent, **imshow_kwargs) X = X - X.min() X /= X.max() / 2. X -= 1 x = np.linspace(extent[0], extent[1], X.shape[0]) y = np.linspace(extent[2], extent[3], X.shape[1]) annotations = Annotations() for n, row in enumerate(annotation): for m, val in enumerate(row): var = X[n][m] annotations.append( Annotation( text=str(val), x=x[m], y=y[n], xref='x1', yref='y1', font=dict( color='white' if np.abs(var) > 0.8 else 'black', size=10), opacity=.5, showarrow=False, )) return imshow, annotations
def make_annotations(pos, text, colorVertex, font_size=14, font_color='rgb(25,25,25)'): L=len(pos[0]) if len(text)!=L: raise ValueError('The lists pos and text must have the same len') annotations = Annotations() for k in range(L): f = getColorText(colorVertex[k]) annotations.append( Annotation( #text=text[k], x=pos[0][k], y=pos[1][k], xref='x1', yref='y1', font=dict(color= f, size=font_size), showarrow=False) ) return annotations
def treeplot(decision_tree): """""" if len(decision_tree.nodes) == 0: return '' g = igraph.Graph() g.add_vertices(len(decision_tree.nodes)) g.add_edges(decision_tree.edges) # Define posições no espaço para a árvore layout = g.layout_reingold_tilford(mode="out", root=[0], rootlevel=None) # Cria os vértices da árvore Xn = [-node[0] for node in layout] Yn = [-node[1] for node in layout] colors = [ '#333' if node['type'] == 'decision' else '#CACACA' for node in decision_tree.nodes ] nodes = Scatter(x=Xn, y=Yn, mode='markers', marker=dict(symbol='square', size=40, color=colors), text=None, hoverinfo='none') # Escreve rótulos nos vértices annotations = Annotations() for node in decision_tree.nodes: color = '#FFF' if node['type'] == 'decision' else '#000' label = node['label'] if node[ 'type'] == 'decision' else node['label'] + '?' a = Annotation(text=label, x=Xn[node['id']], y=Yn[node['id']], xref='x1', yref='y1', font=dict( color=color, size=9, family='"Open Sans", verdana, arial, sans-serif'), showarrow=False) annotations.append(a) # Cria as arestas da árvore Xe = [] Ye = [] for edge in decision_tree.edges: Xe += [Xn[edge[0]], Xn[edge[1]], None] Ye += [Yn[edge[0]], Yn[edge[1]], None] lines = Scatter(x=Xe, y=Ye, mode='lines+markers+text', line=dict(color='#333', width=2), hoverinfo='none') # Escreve rótulos nas arestas for edge in decision_tree.edges: label = decision_tree.nodes[edge[1]]['value'] X = (Xn[edge[0]] + Xn[edge[1]]) / 2 Y = (Yn[edge[0]] * 1.2 + Yn[edge[1]] * 0.8) / 2 a = Annotation(text=label, x=X, y=Y, xref='x1', yref='y1', font=dict( color='#333', size=14, family='"Open Sans", verdana, arial, sans-serif'), showarrow=False) annotations.append(a) # Cria gráfico data = Data([lines, nodes]) axis = dict(showline=False, zeroline=False, showgrid=False, showticklabels=False) layout = dict(title='', annotations=annotations, font=dict(size=12, family='"Open Sans", verdana, arial, sans-serif'), showlegend=False, xaxis=XAxis(axis), yaxis=YAxis(axis), margin=dict(l=0, r=0, b=0, t=0), hovermode='closest', paper_bgcolor='rgba(0,0,0,0)', plot_bgcolor='rgba(0,0,0,0)') fig = dict(data=data, layout=layout) return plot(fig, filename='Decision-Tree', output_type='div', include_plotlyjs=False)
def test_validate_error(): annotations = Annotations() annotations.append({'not-a-key': 'anything'}) annotations.validate()
def test_validate_error(): annotations = Annotations() annotations.append({'not-a-key': 'anything'}) annotations.validate()