Data overlapping on the x-axis of the graph

Asked

Viewed 782 times

1

I need to place a series of dates (timestamp) that are stored in a bd on the x-axis of a graph, the problem is that the dates overlap and it is impossible to perform an efficient analysis. It follows the code:

# -*- coding: utf-8 -*-
import MySQLdb as mdb
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as dates

con = mdb.connect('localhost', 'testuser', '*******', 'testdb')
with con:
    f = []
    cur = con.cursor()
    conversor = dates.strpdate2num('%Y-%m-%d %H:%M:%S')
    a = cur.execute("SELECT Ping FROM Pings WHERE Enderecos ='186.209.34.78'")
    a = cur.fetchall()    
    row = cur.execute("SELECT Timestamp FROM Pings WHERE Enderecos = '186.209.34.78'")
    for i in range(cur.rowcount):   
        row= cur.fetchone()[0]   
        f.append(conversor(row))
    plt.xlabel("Timestamp")
    plt.ylabel("Ping")
    plt.plot_date(f,a)
    plt.title("186.209.34.78")
    plt.show() 

Resultado:

Zooming:inserir a descrição da imagem aqui

  • And if you try to reduce the font size: matplotlib.rcParams.update({'font.size': 10})?

  • I think there is no way to avoid decreasing the font as explained in the post above. Also, I don’t know how this axis timestamp is generated x but vc could try to leave only day and month or else only 2 digits of the year. If the timestamp is created with some function of datetime or something like that and not directly by mpl just processing the string to turn it into a more "nice" (smaller) format. To treat this date, you can use data = '2017-05-28'&#xA;data2 = ''.join([x+'-' if len(x)<4 else data[2:4] for x in reversed(data.split('-'))])

1 answer

1


I believe you can rotate this text using:

plt.xticks(rotation=20)

Upshot: inserir a descrição da imagem aqui

  • Exactly what I needed, thank you! :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.