2017-01-25 36 views

回答

2

您可以:

1)x_label_rotation參數設定值順時針旋轉日期。
2)獲取x軸的每個N日期,其中N可以調整。你應該設置show_minor_x_labels = False。

例如:

import random 
import pygal 
chart = pygal.Line(x_label_rotation=20) 
date_list = [datetime(2017, 1, 30, 0, 0, n) for n in range(0, 60)] 
values_list = [random.randint(5, 20) for n in range(0, 60)] 
chart.x_labels = date_list 
chart.add('line', values_list) 
chart.render_to_file('your_path_to_file') #f.e /Users/{user_name}/Documents/chart.svg 

之後,我們越來越重疊日期:

enter image description here

接下來考慮的代碼修改的摘錄:

import random 
import pygal 
chart = pygal.Line(x_label_rotation=20, show_minor_x_labels=False) 
date_list = [datetime(2017, 1, 30, 0, 0, n) for n in range(0, 60)] 
values_list = [random.randint(5, 20) for n in range(0, 60)] 
chart.x_labels = date_list 
N = 5 # we will plot only every 5 date from date_list 
chart.x_labels_major = date_list[::N] 
chart.add('line', values_list) 
chart.render_to_file('your_path_to_file') #f.e /Users/{user_name}/Documents/chart.svg 

之後,我們AREN重疊日期:

enter image description here

+0

謝謝@Eduard。這非常有幫助。 –

相關問題