教 程 目 录
Seaborn教程
Seaborn是一个开源的,获得BSD许可的Python库,提供高级API,用于使用Python编程可视化数据语言.
受众
本教程将向您介绍Seaborn的基础知识和各种功能.它对从事数据分析的人员特别有用.完成本教程后,您将发现自己具有中等水平的专业知识,从而可以获得更高水平的专业知识.
先决条件
您应该对计算机编程术语有基本的了解.对Python和任何编程语言的基本了解是一个优点. Seaborn库建立在Matplotlib之上.掌握Matplotlib的基本概念将帮助您更好地理解本教程.
本文地址:https://www.itbaoku.cn/tutorial/seaborn-index.html
相关问答
我正在尝试部署一个应用程序,并且进口Seaborn时会崩溃 这是我的配置:Python 2.7,Pyinstaller 3.3.1,Seaborn 0.8.1. 这是我在installTest.py.py 中编写的最简单的代码 import seaborn print 'It works now!' 然后在控制台i键入pyinstaller .\installTest 我获得了一个长的错误代码,该messagesstream未找到messagesstream模块. 您对如何解决这个问题有任何想法吗? 解决方案 我发现了我的问题. 首先,这是使小示例起作用的原因:我修改了我的.spec文件以包括一些隐藏的进口和一些熊猫和海洋的东西 # -*- mode: python -*- block_cipher = None def get_seaborn_path(): import seaborn seaborn_path = seaborn.__path__[0] return seaborn_path def get_pandas_path(): import pandas pandas_path = pandas.__path__[0] return pandas_path a
)
我正在尝试将传说添加到我的seaborn bar绘图中.我已经尝试添加色调,但是它突然出现了错误的错误,因此我通过给出标签参数尝试了其他解决方案.这是代码 plt.figure(figsize=[15,12]) sns.barplot(x=customer['gender'].unique(),y=customer.groupby(['gender'])['gender'].count(), data=customer,label=customer['gender'].unique()) plt.legend(loc="upper left") 这是结果,此结果是错误的.根据酒吧中的颜色,它应该具有女性和男性标签.男性和男性应该用不同的颜色分开.我已经尝试关注 this , this 和 解决方案 这是您可以在现有代码中使用handles参数的一个衬里: patches = [matplotlib.patches.Patch(color=sns.color_palette()[i], label=t) for i,t in enumerate(t.get_text() for t in plot.get_xticklabels())] 这样使用: plt.legend(handles
)
我正在运行以下代码并获得此问题 - "/usr/local/lib/python2.7/dist-ackages/seaborn/limeseries.py:183:userWarning:将来删除了tsplot功能,将来将删除或更换(以实质性更改的版本)发布. WARNINGS.WARN(MSG,用户沃宁) ". 有人知道如何解决此问题吗? 代码 - import numpy as np import tensorflow as tf import seaborn as sns import pandas as pd SEQ_LEN = 10 def create_time_series(): freq = (np.random.random()*0.5) + 0.1 # 0.1 to 0.6 ampl = np.random.random() + 0.5 # 0.5 to 1.5 x = np.sin(np.arange(0,SEQ_LEN) * freq) * ampl return x for i in xrange(0, 5): sns.tsplot( create_time_series() ); # 5 series 解决方案 根据注释:这是一个警告,而不是错误.您被警告说,您使用的功能将来会从Seaborn
)
我在python panda dataframe中有以下数据.我想将类似于 htttps "> htttps://stanford中的盒子图分组. edu/〜mwaskom/software/seaborn/示例/grouped_boxplot.html 对于每个ID,我想并排绘制两个盒子图.我如何实现这一目标.我尝试用海洋包裹绘制它,但没有任何成功. id predicted real 1 [10, 10, 10] [16, 18, 20] 2 [12, 12, 15] [15, 17, 19, 21, 23] 3 [20, 5, 4, 4] [29, 32] 4 [25, 25, 25, 24, 21] [21, 24, 25, 26, 28, 29, 30, 33] 5 [20, 20, 20, 21] [21, 22, 24, 26, 28, 30, 31, 32] 6 [8, 3, 3, 14] [
)
我正在用Seaborn的regplot绘制一些东西.据我了解,它在幕后使用pyplot.scatter.因此,我假设如果我为satterplot指定颜色为序列,那么我就可以调用plt.colorbar,但似乎不起作用: sns.regplot('mapped both', 'unique; repeated at least once', wt, ci=95, logx=True, truncate=True, line_kws={"linewidth": 1, "color": "seagreen"}, scatter_kws={'c':wt['Cis/Trans'], 'cmap':'summer', 's':75}) plt.colorbar() Traceback (most recent call last): File "", line 2, in plt.colorbar() File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 2152, in colorbar raise RuntimeError('No mappable was found to use
)
在Seaborn中,色调为小组设定了不同的颜色.我可以根据JointGrid的组设置alpha吗?甚至在单个数据点上? sns.set_theme() jg = sns.JointGrid(data=df_sns, x='x', y='y', hue='hue') jg.plot_joint(sns.scatterplot) jg.plot_marginals(sns.histplot, kde=False) jg.set_axis_labels(xlabel='x', ylabel='y') jg.fig.tight_layout() 解决方案 (更新:使用to_rgba(),如评论中所建议的.) 您可以创建一个包含alpha颜色的palette.创建这种颜色的一种简单方法是使用十六进制格式:'#RRGGBBAA'.或者,您可以将任何matplotlib颜色转换为RGB并添加alpha,如示例代码: 中 import matplotlib.pyplot as plt from matplotlib.colors import to_rgba import seaborn as sns iris = sns.load_dataset("iris") g = sns.JointGrid(data=iris, x='sepal_length', y='sep
)