|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
用户pycharm练习的时候无法正常运行,源码# coding=utf-8
from matplotlib import pyplot as plt
import random
import matplotlib
font = {'family': 'Microsoft YaHei',
'weight': 'bold',
'size': '18'}
matplotlib.rc("font",**font)
x: range = range(2,42,2)
y = [random.randint(10,20) for i in range(20)]
fig = plt.figure(figsize=(20,15),dpi=300)#设置图片大小(长,宽)以及分辨率
plt.plot(x,y)
#调整X,Y的坐标
xtick_labels = ["10点{}分".format(i) for i in range(10)]
xtick_labels += ["11点{}分".format(i) for i in range(10)]
plt.xticks(list(x)[::3],xtick_labels[::3],rotation=90)
plt.yticks(range(10,20))
plt.savefig("./test.png")#保存图片到指定路径,格式只能为eps, pdf, pgf, png, ps, raw, rgba, svg(矢量图,放大不会有锯齿), svgz
plt.show()
跳错:Traceback (most recent call last):
File "F:\python\PyCharm 2020.1.1\plugins\python\helpers\pycharm_display\datalore\display\display_.py", line 60, in _send_display_message
urlopen(url, buffer)
File "F:\python\python38\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "F:\python\python38\lib\urllib\request.py", line 525, in open
response = self._open(req, data)
File "F:\python\python38\lib\urllib\request.py", line 542, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "F:\python\python38\lib\urllib\request.py", line 502, in _call_chain
result = func(*args)
File "F:\python\python38\lib\urllib\request.py", line 1379, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "F:\python\python38\lib\urllib\request.py", line 1354, in do_open
r = h.getresponse()
File "F:\python\python38\lib\http\client.py", line 1332, in getresponse
response.begin()
File "F:\python\python38\lib\http\client.py", line 303, in begin
version, status, reason = self._read_status()
File "F:\python\python38\lib\http\client.py", line 264, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "F:\python\python38\lib\socket.py", line 669, in readinto
return self._sock.recv_into(b)
ConnectionAbortedError: [WinError 10053] 你的主机中的软件中止了一个已建立的连接。
求大佬帮忙解答一下,谢谢
试试这个代码:
from matplotlib import pyplot as plt
import random
plt.rcParams['font.sans-serif'] = ['SIMHEI']
x: range = range(2,42,2)
y = [random.randint(10,20) for i in range(20)]
fig = plt.figure(figsize=(15,8),dpi=100)#设置图片大小(长,宽)以及分辨率
plt.plot(x,y)
#调整X,Y的坐标
xtick_labels = ["10点{}分".format(i) for i in range(10)]
xtick_labels += ["11点{}分".format(i) for i in range(10)]
plt.xticks(list(x)[::3],xtick_labels[::3],rotation=90)
plt.yticks(range(10,20))
plt.savefig("./test.png")#保存图片到指定路径,格式只能为eps, pdf, pgf, png, ps, raw, rgba, svg(矢量图,放大不会有锯齿), svgz
plt.show()
|
|