Ir para conteúdo
Fórum Script Brasil

Daniel Chagas Machado

Membros
  • Total de itens

    1
  • Registro em

  • Última visita

Sobre Daniel Chagas Machado

Daniel Chagas Machado's Achievements

0

Reputação

  1. Pessoal, bom dia. Estou iniciando em Python e me deparei com 3 problemas. Estou tentando criar um gráfico de linhas, com 02 linhas, com o seguinte código, que peguei diretamente na biblioteca do pacote Altair: import altair as alt import pandas as pd import numpy as np np.random.seed(42) source = pd.DataFrame(np.cumsum(np.random.randn(24, 3), 0).round(2), columns=['A', 'B', 'C'], index=pd.RangeIndex(24, name='x')) source = source.reset_index().melt('x', var_name='category', value_name='y') # Create a selection that chooses the nearest point & selects based on x-value nearest = alt.selection(type='single', nearest=True, on='mouseover', fields=['x'], empty='none') # The basic line line = alt.Chart(source).mark_line(interpolate='basis').encode( x='x:Q', y='y:Q', color='category:N' ) # Transparent selectors across the chart. This is what tells us # the x-value of the cursor selectors = alt.Chart(source).mark_point().encode( x='x:Q', opacity=alt.value(0), ).add_selection( nearest ) # Draw points on the line, and highlight based on selection points = line.mark_point().encode( opacity=alt.condition(nearest, alt.value(1), alt.value(0)) ) # Draw text labels near the points, and highlight based on selection text = line.mark_text(align='left', dx=5, dy=-5).encode( text=alt.condition(nearest, 'y:Q', alt.value(' ')) ) # Draw a rule at the location of the selection rules = alt.Chart(source).mark_rule(color='gray').encode( x='x:Q', ).transform_filter( nearest ) # Put the five layers into a chart and bind the data alt.layer( line, selectors, points, rules, text ).properties( width=1500, height=300 ) No entanto, não consegui fazer com que meu documento (.csv) fosse aberto e lido corretamente. E também não consegui mudar o início do eixo x. Começa no "0", e gostaria de iniciar no 1 ou em algum outro número que esteja no index no arquivo anexo. Link do arquivo com os dados. https://drive.google.com/file/d/154jTl4zwNJ-1wSGZCurItqFhv-lsM7vf/view?usp=sharing Outra questão é... consigo mesclar esse gráfico de linhas com gráfico de barras? Obrgado,
×
×
  • Criar Novo...