python在绘制图像时候,x轴的坐标未能显示

python在绘制图像时候,x轴的坐标未能显示。

显示的图片如下:
图片说明

代码如下(本人用的是 jupyter notebook):

import urllib.request
import json
import pygal
import math
from itertools import groupby

# json_url = "https://raw.githubusercontent.com/muxuezi/btc/master/btc_close_2017.json"
# req = urllib.request.urlopen(json_url)
# json = req.read()
# #将数据写入文件
# with open("E:/Jupyter/json收盘数据.json","wb") as f:
#     f.write(json)

filename = "E:/Jupyter/json收盘数据.json"
with open(filename) as f:
    btc_data = json.load(f)

# #打印每一天的信息(获取数据过程)
# for btc_dict in btc_data:
#    data = btc_dict["date"]
#    month = int(btc_dict["month"])
#    week = int(btc_dict["week"])
#    weekday = btc_dict["weekday"]
#    close = int(float(btc_dict["close"]))
#    print("{} is month {} week {},{},the close price is {}RMB".format(data,month,weekday,weekday,close))

#绘制收盘价折线图
dates = []
month = []
weeks = []
weekdays = []
close = []
#每一天信息
for btc_dict in btc_data:
    dates.append(btc_dict["date"])
    month.append(int(btc_dict["month"]))
    weeks.append(int(btc_dict["week"]))
    weekdays.append(btc_dict["weekday"])
    close.append(int(float(btc_dict["close"])))

#绘制收盘价对数变换价折线图
line_chart = pygal.Line(x_label_rotation = 20,show_minor_x_labels = True)
line_chart.title = "收盘价"
line_chart.x_label = dates
N = 20 #x轴每隔20天显示一次
line_chart.x_labels_major = dates[::N]
close_log = [math.log10(_) for _ in close]
line_chart.add("收盘价",close_log)
line_chart.render_to_file("收盘对数变换价折现图.svg")
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问