温度折线图

<html lang="en">
<head>
    <script type="text/javascript" src="http://cdn.hcharts.cn/jquery/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="http://cdn.hcharts.cn/highcharts/highcharts.js"></script>
    <script type="text/javascript" src="http://cdn.hcharts.cn/highcharts/exporting.js"></script>
    <script>
        $(function () {
            $('#container').highcharts({
                chart: {
                    type: 'line'
                },
                title: {
                    text: '我的第一个可视化'
                },
                subtitle: {
                    text: '嗯 这个相对容易操作'
                },
                xAxis: {
                    categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
                },
                yAxis: {
                    title: {
                        text: 'Temperature (°C)'
                    }
                },
                tooltip: {
                    enabled: false,
                    formatter: function () {
                        return '<b>' + this.series.name + '</b>' + this.x + ': ' + this.y + '°C';
                    }
                },
                plotOptions: {
                    line: {
                        dataLabels: {
                            enabled: true
                        },
                        enableMouseTracking: false
                    }
                },
                series: [{
                    name: 'A城市',
                    data: [7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
                }, {
                    name: 'B城市',
                    data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6,4.8]
                }]
            });
        });
    </script>
</head>
<body>
    <div id="container" style="min-width:700px;height:400px"></div>
</body>
</html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,要实现这个功能,你可以首先使用Python的request库来获取天气数据。可以使用以下代码: ```python import requests # 设置url和headers url = 'http://tianqiapi.com/api' headers = {'User-Agent': 'Mozilla/5.0'} # 根据接口要求设置相应的查询参数 params = { 'version': 'v61', 'appid': 'YourAppID', 'appsecret': 'YourAppSecret', 'cityid': '101010100', 'start_date': '20230201', 'end_date': '20230215' } # 发送请求 response = requests.get(url, params=params, headers=headers) # 打印响应结果 print(response.json()) ``` 其中,`YourAppID` 和 `YourAppSecret` 可以在天气接口平台上申请获得,`cityid` 表示查询城市的编号,这里使用的是北京市的编号。 接下来,你可以解析响应结果,获取每天的最高温度和最低温度,并将数据存储到一个列表中。可以使用以下代码实现: ```python import pandas as pd import matplotlib.pyplot as plt # 解析响应结果 data = response.json()['data'] # 获取每天的最高温度和最低温度 temperatures = [] for day in data: high_temp = float(day['tem1']) low_temp = float(day['tem2']) temperatures.append({'date': day['date'], 'high_temp': high_temp, 'low_temp': low_temp}) # 将数据存储到DataFrame中 df = pd.DataFrame(temperatures) # 绘制折线图 plt.plot(df['date'], df['high_temp'], label='highest temperature') plt.plot(df['date'], df['low_temp'], label='lowest temperature') plt.legend() plt.title('YourName-YourStudentID-Temperature Chart') plt.xlabel('Date') plt.ylabel('Temperature') plt.show() ``` 最后,你可以运行以上代码,生成温度折线图,并将其保存下来。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值