Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

245
Views
Cómo trazar mi marco de datos de pandas en matplotlib

Tengo el siguiente código:

 import matplotlib.pyplot as plt import numpy as np import pandas as pd data = pd.read_csv("Ari_atlag.txt", sep = '\t', header = 0) #Num_array = pd.DataFrame(data).to_numpy() print(data.head()) data.plot() #data.columns = ['Date', 'Number_of_test', 'Avarage_of_ARI'] #print(Num_array) plt.show()

Producción:

 Date Number_of_test Avarage_of_ARI 0 2011-01 22 0.568734 1 2011-02 5 0.662637 2 2011-03 0 0.000000 3 2011-04 3 0.307692 4 2011-05 6 0.773611 Process finished with exit code 0

y la trama.

Pero con este código en la trama, el eje x es el índice. Pero quiero obtener la Fecha en el eje x.

Cómo trazar la Fecha con Número_de_prueba y Fecha con Avarage_of_ARI

Creo que de alguna manera debería cambiar la cadena (fecha) a las fechas, pero no sé cómo hacerlo.

Mejor

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Prueba esto :

 #Excutable example df = pd.DataFrame({"Date" : ["2011-01", "2011-02", "2011-03", "2011-04", "2011-05"], "Number_of_test" : [22, 5, 0, 3, 6], "Avarage_of_ARI" : [0.568734, 0.662637, 0.000000, 0.307692, 0.773611]}) df.Date = pd.to_datetime(df.Date) df = df.set_index("Date")

Gráfico

 plt.style.use('ggplot') plt.rcParams['figure.figsize'] = [13,5] data_ax1 = df.Number_of_test data_ax2 = df.Avarage_of_ARI fig, ax1 = plt.subplots() ax1.set_ylabel('Number_of_test', color = 'tab:red') ax1.plot(data_ax1, color = 'tab:red', linewidth= 1) ax1.tick_params(axis = 'y', labelcolor= 'tab:red', length = 6, width = 1, grid_alpha=0.5) ax2 = ax1.twinx() ax2.set_ylabel('Avarage_of_ARI', color = 'tab:blue') ax2.plot(data_ax2, color = 'tab:blue', linewidth = 1) ax2.tick_params(axis='y', labelcolor = 'tab:blue') fig.tight_layout() plt.title("Plot", fontsize = 15)

Resultado ingrese la descripción de la imagen aquí

over 4 years ago · Santiago Trujillo Report

0

Use x='Date' como parámetro de la plot :

 df.plot(x='Date') plt.show()

ingrese la descripción de la imagen aquí

over 4 years ago · Santiago Trujillo Report

0

Puede establecer el índice en la columna de fecha si eso funciona para sus datos.

 cols = ['Number_of_test','Avarage_of_ARI'] data.set_index('Date', inplace = True) for c in cols: data[c].plot()
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!