ckj1229119505 2023-02-25 22:26 采纳率: 100%
浏览 18
已结题

python数据可视化 报错

请问最后my_layout部分为何会报错?

img


import requests
from plotly.graph_objs import Bar
from plotly import offline

url = 'https://api.github.com/search/repositories?q=language:python&sort=stars'
headers = {'Accept': 'application/vnd.github.v3+json'}
r = requests.get(url, headers=headers)
print(f'Status code: {r.status_code}')

# 处理结果
response_dict = r.json()
repo_dicts = response_dict['items']
repo_names, stars = [], []
for repo_dict in repo_dicts:
    repo_names.append(repo_dict['name'])
    stars.append(repo_dict['stargazers_count'])

# 可视化
data = [{
    'type': 'bar',
    'x': repo_names,
    'y': stars,
    'marker': {
        'color': 'rgb(60, 100, 150)',
        'line': {'width': 1.5, 'color': 'rab(25, 25, 25)'},
    },
    'opacity': 0.6,
}]
my_layout = {
    'title': "Github上最受欢迎的Python项目",
    'titlefont': {'size': 28},
    'xaxis': {
        'title': 'Repositories'
        'titlefont':  {'size': 24},
        'tickfont' : {'size': 14},
    },
    'yaxis': {
        'title': 'Stars',
        'tickfont': {'size': 24},
        'tickfont': {'size': 14},
    },
}

fig = {'data': data, 'layout': my_layout}
offline.plot(fig, filename='python_repo.html')
  • 写回答

2条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      问题事件

      • 系统已结题 3月5日
      • 已采纳回答 2月25日
      • 创建了问题 2月25日

      悬赏问题

      • ¥100 微信会员卡如何外接除本用户外的商户从而可以进行优惠支付
      • ¥50 关于github项目下载运行
      • ¥15 苹果手机删除了qq软件,qq文件怎么恢复
      • ¥20 用mips 人力编程排序问题(能在mars按要求运行)
      • ¥15 Verilog小型神经网络(单层反馈神经网络)
      • ¥15 设计一个数字钟,实现时分秒的显示
      • ¥15 Clion使用头文件链接两个cpp
      • ¥15 51单片机无法触发外部中断问题
      • ¥15 基于半监督,无监督的调制识别
      • ¥15 cst求 阵列 rcs 时候 频域 时域求解器 应该怎样设置 才让两者 计算结果 相似 请附图