【问题标题】:sns.set_style() command is not working on my code,please assistsns.set_style() 命令不适用于我的代码,请协助
【发布时间】:2022-01-26 01:27:30
【问题描述】:

我尝试在我的代码中使用 seaborn 包来散布图复数,但即使在调用 sns.set_style() 之后我也没有得到任何输出。请帮忙。

from matplotlib import pyplot as plt
import math
import seaborn as sns
s = ([1 + 1j, 1 + 69j, 2 + 1j, 2 + 2j,4.5 - 6.4j])  # s is a list which contains all the complex numbers which r to be plotted
                  
            x = [x.real for x in s]
            y = [y.imag for y in s]
            plt.plot(x, y, 'o', c='red')
            plt.grid(True)
            plt.xlabel('Real number')
            plt.ylabel('Imaginary number')
            plt.title('Graph of given complex numbers')
            sns.set_style("dark")
            plt.show()```

【问题讨论】:

    标签: python matplotlib numbers seaborn


    【解决方案1】:

    请在#sns.set_style#之前添加“sns.set_theme()” 从 matplotlib 导入 pyplot 作为 plt 导入数学 将 seaborn 导入为 sns s = ([1 + 1j, 1 + 69j, 2 + 1j, 2 + 2j,4.5 - 6.4j]) # s 是一个列表,其中包含 r 要绘制的所有复数

            x = [x.real for x in s]
            y = [y.imag for y in s]
            plt.plot(x, y, 'o', c='red')
            plt.grid(True)
            plt.xlabel('Real number')
            plt.ylabel('Imaginary number')
            plt.title('Graph of given complex numbers')
            sns.set_theme() # to make style changable from defaults use this line of code befor using set_style
            sns.set_style("dark")
            plt.show()
    

    我希望现在可以运行

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-18
      • 2014-07-02
      • 1970-01-01
      • 2013-03-01
      • 1970-01-01
      • 2015-12-10
      • 2016-01-01
      • 2014-06-24
      相关资源
      最近更新 更多