|
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
# 通过rcParams设置全局横纵轴字体大小
mpl.rcParams['xtick.labelsize'] = 24
mpl.rcParams['ytick.labelsize'] = 24
np.random.seed(42)
# x轴的采样点
x = np.linspace(0, 5, 100)
# 通过下面曲线加上噪声生成数据,所以拟合模型就用y了……
y = 2 * np.sin(x) + 0.3 * x ** 2
y_data = y + np.random.normal(scale=0.3, size=100)
# figure()指定图表名称
plt.figure('data')
# '.'标明画散点图,每个散点的形状是个圆
plt.plot(x, y_data, '.')
# 画模型的图,plot函数默认画连线图
plt.figure('model')
plt.plot(x, y)
# 两个图画一起
plt.figure('data & model')
# 通过'k'指定线的颜色,lw指定线的宽度
# 第三个参数除了颜色也可以指定线形,比如'r--'表示红色虚线
# 更多属性可以参考官网:http://matplotlib.org/api/pyplot_api.html
plt.plot(x, y, 'k', lw=3)
# scatter可以更容易地生成散点图
plt.scatter(x, y_data)
# 将当前figure的图保存到文件result.png
plt.savefig('result.png')
# 一定要加上这句才能让画好的图显示在屏幕上
plt.show()
出现问题:D:\pycharmfiles\new\Scripts\python.exe "F:\PyCharm 2019.1.1\helpers\pydev\pydevconsole.py" --mode=client --port=5760Traceback (most recent call last): File "F:\PyCharm 2019.1.1\helpers\pydev\pydevconsole.py", line 33, in <module> from _pydev_bundle.pydev_console_utils import BaseInterpreterInterface File "F:\PyCharm 2019.1.1\helpers\pydev\_pydev_bundle\pydev_console_utils.py", line 11, in <module> from _pydevd_bundle import pydevd_thrift File "F:\PyCharm 2019.1.1\helpers\pydev\_pydevd_bundle\pydevd_thrift.py", line 17, in <module> from pydev_console.protocol import DebugValue, GetArrayResponse, ArrayData, ArrayHeaders, ColHeader, RowHeader, \ File "F:\PyCharm 2019.1.1\helpers\pydev\pydev_console\protocol.py", line 6, in <module> _console_thrift = _shaded_thriftpy.load(os.path.join(os.path.dirname(os.path.realpath(__file__)), "console.thrift"), File "F:\PyCharm 2019.1.1\helpers\third_party\thriftpy\_shaded_thriftpy\parser\__init__.py", line 29, in load thrift = parse(path, module_name, include_dirs=include_dirs, File "F:\PyCharm 2019.1.1\helpers\third_party\thriftpy\_shaded_thriftpy\parser\parser.py", line 502, in parse parser.parse(data) File "F:\PyCharm 2019.1.1\helpers\third_party\thriftpy\_shaded_ply\yacc.py", line 331, in parse return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc) File "F:\PyCharm 2019.1.1\helpers\third_party\thriftpy\_shaded_ply\yacc.py", line 1106, in parseopt_notrack p.callable(pslice) File "F:\PyCharm 2019.1.1\helpers\third_party\thriftpy\_shaded_thriftpy\parser\parser.py", line 212, in p_struct val = _fill_in_struct(p[1], p[3]) File "F:\PyCharm 2019.1.1\helpers\third_party\thriftpy\_shaded_thriftpy\parser\parser.py", line 765, in _fill_in_struct gen_init(cls, thrift_spec, default_spec) File "F:\PyCharm 2019.1.1\helpers\third_party\thriftpy\_shaded_thriftpy\thrift.py", line 103, in gen_init cls.__init__ = init_func_generator(default_spec) File "F:\PyCharm 2019.1.1\helpers\third_party\thriftpy\_shaded_thriftpy\_compat.py", line 102, in init_func_generator new_code = types.CodeType(len(varnames),TypeError: an integer is required (got type bytes)Process finished with exit code 1
请高手帮忙解决下?
|
|