{
"code": "# 保存绘制的气温折线图为图片文件\nimport os\n\nimport matplotlib.pyplot as plt\n\n# 从之前整理的字典数据结构获取天气数据\nweather_data = {\n '03月17日': {'最高气温': 16, '最低气温': 12},\n '03月18日': {'最高气温': 21, '最低气温': 12},\n '03月19日': {'最高气温': 22, '最低气温': 11},\n '03月20日': {'最高气温': 22, '最低气温': 11},\n '03月21日': {'最高气温': 24, '最低气温': 12},\n '03月22日': {'最高气温': 25, '最低气温': 13},\n '03月23日': {'最高气温': 26, '最低气温': 14}\n}\n\n# 提取日期、最高气温和最低气温\ndates = list(weather_data.keys())\nhighs = [data['最高气温'] for data in weather_data.values()]\nlows = [data['最低气温'] for data in weather_data.values()]\n\n# 创建折线图\nplt.figure(figsize=(10, 5))\nplt.plot(dates, highs, marker='o', label='最高气温 (℃)', color='red')\nplt.plot(dates, lows, marker='o', label='最低气温 (℃)', color='blue')\n\n# 添加标题和标签\nplt.title('未来一周广州天气气温折线图')\nplt.xlabel('日期')\nplt.ylabel('气温 (℃)')\nplt.xticks(rotation=45)\nplt.legend()\nplt.grid()\n\nprint(os.getcwd())\n\n# 保存图形为PNG文件\nplt.savefig('guangzhou_weather_temperature_chart.png')\nplt.close()\nprint(11)",
"is_download": true
}
curl --location --request POST 'https://api.302.ai/302/sandbox/direct_run_code' \
--header 'Authorization: Bearer sk-mfYQzy0XTFfz4P16vRE4gFrKK1Nly4TozsMqbbb9PSiJUvFO' \
--header 'Content-Type: application/json' \
--data-raw '{
"code": "# 保存绘制的气温折线图为图片文件\nimport os\n\nimport matplotlib.pyplot as plt\n\n# 从之前整理的字典数据结构获取天气数据\nweather_data = {\n '\''03月17日'\'': {'\''最高气温'\'': 16, '\''最低气温'\'': 12},\n '\''03月18日'\'': {'\''最高气温'\'': 21, '\''最低气温'\'': 12},\n '\''03月19日'\'': {'\''最高气温'\'': 22, '\''最低气温'\'': 11},\n '\''03月20日'\'': {'\''最高气温'\'': 22, '\''最低气温'\'': 11},\n '\''03月21日'\'': {'\''最高气温'\'': 24, '\''最低气温'\'': 12},\n '\''03月22日'\'': {'\''最高气温'\'': 25, '\''最低气温'\'': 13},\n '\''03月23日'\'': {'\''最高气温'\'': 26, '\''最低气温'\'': 14}\n}\n\n# 提取日期、最高气温和最低气温\ndates = list(weather_data.keys())\nhighs = [data['\''最高气温'\''] for data in weather_data.values()]\nlows = [data['\''最低气温'\''] for data in weather_data.values()]\n\n# 创建折线图\nplt.figure(figsize=(10, 5))\nplt.plot(dates, highs, marker='\''o'\'', label='\''最高气温 (℃)'\'', color='\''red'\'')\nplt.plot(dates, lows, marker='\''o'\'', label='\''最低气温 (℃)'\'', color='\''blue'\'')\n\n# 添加标题和标签\nplt.title('\''未来一周广州天气气温折线图'\'')\nplt.xlabel('\''日期'\'')\nplt.ylabel('\''气温 (℃)'\'')\nplt.xticks(rotation=45)\nplt.legend()\nplt.grid()\n\nprint(os.getcwd())\n\n# 保存图形为PNG文件\nplt.savefig('\''guangzhou_weather_temperature_chart.png'\'')\nplt.close()\nprint(11)",
"is_download": true
}'
{"result":{"stdout":["/home/user\n","11\n"],"stderr":[],"file":{"url":"https://file.302.ai/gpt/imgs/20250325/32b6d14175364c9aba38c68caa8158c3.7z"}}}