Fanqiepy 2021-06-17 09:22 采纳率: 66.7%
浏览 29
已结题

python 中文显示求解

请问各位大神这段代码,中文无法显示,这么解决!

import csv
import matplotlib.pyplot as plt

from pylab import *#显示中文字符代码
mpl.rcParams["font.sans-serif"]=["SimHei"]#显示中文字符代码

from datetime import datetime 

filename ="sitka_weather_2018_simple.csv"
with open(filename) as f:
	reader = csv.reader(f)
	header_row = next(reader)
	dates,highs,lows = [],[],[]
	for row in reader:
		current_date = datetime.strptime(row[2],"%Y-%m-%d")
		try:
			high = int(row[5])
			low = int(row[6])
		except:
			print(f"missing data of {current_date}")
		else:
			highs.append(high)
			lows.append(low)
			dates.append(current_date)
plt.style.use("seaborn")
fig,ax = plt.subplots()
ax.plot(dates,highs,c="red",alpha =0.2)
ax.plot(dates,lows,c="blue",alpha = 0.2)
ax.fill_between(dates,highs,lows,facecolor = "green",alpha = 0.3)
ax.set_xlabel("",fontsize = 15)
fig.autofmt_xdate()
ax.set_ylabel("温度(F)",fontsize= 15)
ax.set_title("2018年度7月份每日最高温度",fontsize=15)
ax.tick_params(axis ="both",which ="major",labelsize = 15)
plt.show()
  • 写回答

1条回答 默认 最新

  • 小P聊技术 2021-06-17 09:56
    关注

    没有你的csv文件测试不了,我的加这两个就好了:

    plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
    plt.rcParams['axes.unicode_minus']=False #用来正常显示负号

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 5月16日

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试