帮我看看行吗?我实在不知道是怎么回事。

这是今天的一个错误(昨天用还没有报错),是想试试《python编程——从入门到实践》这本书里面的随机漫步,代码和错误都在这里,帮我看看行吗?
img

img

pycharm中报错:Error: failed to send plot to http://127.0.0.1:63342_是否龍磊磊真的一无所有的博客-CSDN博客 pycharm中报错:Error: failed to send plot to http://127.0.0.1:63342import matplotlib.pyplot as pltimport matplotlib.pyplot as pltplt.title("test")plt.xlabel('x')plt.ylabel('y')plt.savefig('test1.jpg')plt.show()在pycharm画图过程中,出现了这个错误.在pycharm使用matplotl https://blog.csdn.net/qq_32998593/article/details/115014919
试试这个?
有帮助望采纳

26行代码绘制散点图的时候有点bug哦

c:表示颜色r:red红色

plt.scatter(rw.x, rw.y, c='r', s=20)

效果图如下:

img

可以绘制个更好看的样式哦

img

from random import choice

import matplotlib.pyplot as plt


class Randomwalk():
    def __init__(self, num=1000):
        self.x = [0]
        self.y = [0]
        self.num = num

    def walk(self):
        while len(self.x) < self.num:
            x_direction = choice([-1, 1])
            x_distance = choice([0, 1, 2, 3, 4, 5])
            x_move = x_direction * x_distance

            y_direction = choice([-1, 1])
            y_distance = choice([0, 1, 2, 3, 4, 5])
            y_move = y_direction * y_distance

            if x_move == 0 and y_move == 0:
                continue
            next_x = self.x[-1] + x_move
            next_y = self.y[-1] + y_move
            self.x.append(next_x)
            self.y.append(next_y)


rw = Randomwalk(num=1000)
rw.walk()
plt.figure(figsize=(10, 6))
# 点的大小s:80,颜色r: 红色,点样式*:五角星
plt.scatter(rw.x, rw.y, c='r', marker='*', s=80)
plt.show()

更多点的样式和颜色可参考:
Matplot pyplot绘制单图,多子图不同样式详解,这一篇就够了_程序媛一枚~的博客-CSDN博客 matplotlib.pyplot 是使 matplotlib 像 MATLAB 一样工作的函数集合。这篇博客将介绍 1. 单图单线2. 单图多线不同样式(红色圆圈、蓝色实线、绿色三角等)3. 使用关键字字符串绘图(data 可指定依赖值为:numpy.recarray 或 pandas.DataFrame)4. 使用分类变量绘图(绘制条形图、散点图、折线图)5. 多子表多轴及共享轴6. 多子表(水平堆叠、垂直堆叠、水平垂直堆叠、水平垂直堆叠共享轴、水平垂直堆叠去掉子图中间的冗余xy https://blog.csdn.net/qq_40985985/article/details/119643704

如有帮助请采纳哦~