seaborn 中是否有默认函数/方法可以重命名箱线图的 xticks 而无需更改输入数据框?
我在文档中没有看到任何内容,也没有在谷歌上搜索这个
我试图将绘图彼此靠近,但这会导致错误:
sns.set_style('darkgrid')
f , axes =plt.subplots(1, 2, figsize=(15,15))
sns.boxplot(data=df, x='Month', y='Price', ax=axes[0,0])
sns.boxplot(data=df, x='Year', y='Price', ax=axes[0,1])
Run Code Online (Sandbox Code Playgroud)
这是错误:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
/tmp/ipykernel_33/3036328835.py in <module>
2 f , axes =plt.subplots(1, 2, figsize=(15,15))
3
----> 4 sns.boxplot(data=df, x='Month', y='Price', ax=axes[0,0])
5 sns.boxplot(data=df, x='Year', y='Price', ax=axes[0,1])
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed
Run Code Online (Sandbox Code Playgroud) 我正在尝试重新创建一个用 seaborn 制作的图,distplot但使用displot, 因为distplot正在折旧。
如何使displot两列重叠?
这是使用以下命令创建的原始代码distplot:
import pandas as pd
import numpy as np
import seaborn as sns
df1 = pd.DataFrame({'num1':np.random.normal(loc=0.0, scale=1.0, size=100),'num2':np.random.normal(loc=0.0, scale=1.0, size=100)})
sns.distplot(df1['num1'],hist=False,color='orange',)
sns.distplot(df1['num2'],hist=False,color='blue')
Run Code Online (Sandbox Code Playgroud)
这是使用绘图的代码displot
sns.displot(data = df1, x = 'num1',color='orange', kind = 'kde')
sns.displot(data = df1, x = 'num2',color='blue', kind = 'kde')
Run Code Online (Sandbox Code Playgroud)
我正在 matplotlib 中编写代码以在子图网格下打印多个直方图,但是,当我最后调用 Fig.legend() 函数时,每个图的图例都会打印两次。任何有关如何解决此问题的指导将不胜感激:)这是我的代码:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('darkgrid')
def get_cmap(n, name='hsv'):
return plt.cm.get_cmap(name, n)
def isSqrt(n):
sq_root = int(np.sqrt(n))
return (sq_root*sq_root) == n
df = pd.read_csv('mpg.csv')
df2 = pd.read_csv('dm_office_sales.csv')
df['miles'] = df2['salary']
numericClassifier = ['int16', 'int32', 'int64', 'float16', 'float32', 'float64']
newdf = df.select_dtypes(numericClassifier)
columns = newdf.columns.tolist()
n = len(columns)
cmap = get_cmap(n)
if(isSqrt(n)):
nrows = ncols = int(np.sqrt(n))
else:
ncols = int(np.sqrt(n))
for i in range(ncols,50): …Run Code Online (Sandbox Code Playgroud) 我需要显示条形图的百分比。但是我不知道该怎么做。
sns.set_style('whitegrid')
sns.countplot(y='type',data=df,palette='colorblind')
plt.xlabel('Count')
plt.ylabel('Type')
plt.title('Movie Type in Disney+')
plt.show()
Run Code Online (Sandbox Code Playgroud)
我有一个 pandas 数据框df,并尝试使用 seaborn 库来创建小提琴图。
rank sentiment category
0 1 0.657413 m
1 2 0.895769 m
2 3 -0.435457 m
3 4 -0.717959 m
4 5 0.869688 m
Run Code Online (Sandbox Code Playgroud)
这是seaborn线路:
sns.violinplot(x="rank", y="senitment", hue="category", data=df)
Run Code Online (Sandbox Code Playgroud)
我不断收到这个ValueError
ValueError: Could not interpret input 'senitment'
Run Code Online (Sandbox Code Playgroud)
全程追溯
violinplot 中的 /Users/jrs/anaconda/lib/python3.5/site-packages/seaborn/categorical.py(x,y,色调,数据,顺序,hue_order,bw,剪切,比例,scale_hue,网格大小,宽度,内部、分割、方向、线宽、颜色、调色板、饱和度、ax、**kwargs)2299 bw、剪切、缩放、scale_hue、网格大小、2300 宽度、内部、分割、方向、线宽、-> 2301 颜色、调色板、饱和度)第2302章 2303、如果ax是无:
/Users/jrs/anaconda/lib/python3.5/site-packages/seaborn/categorical.py in __init__(self, x, y, hue, data, order, hue_order, bw, cut, scale, scale_hue, gridsize, width, inner, split, orient, linewidth, color, palette, saturation)
535 color, palette, saturation):
536
--> …Run Code Online (Sandbox Code Playgroud) 我有一个案例和控制样本列表,以及每个样本中存在或不存在哪些特征的信息.包含信息的数据帧可以由Pandas生成:
import pandas as pd
df={'Patient':[True,True,False],'Control':[False,True,False]} # Presence/absence data for three genes for each sample
df=pd.DataFrame(df)
df=df.transpose()
df.columns=['GeneA','GeneB','GeneC']
Run Code Online (Sandbox Code Playgroud)
我需要将这些数据可视化为点图/散点图,使得x和y轴都是分类的,并且存在/不存在由不同的形状编码.如下:
Patient| x x -
Control| - x -
__________________
GeneA GeneB GeneC
Run Code Online (Sandbox Code Playgroud)
我是Matplotlib/seaborn的新手,我可以绘制简单的线图和散点图.但在线搜索我找不到类似于我需要的任何说明或情节.
我有一个 Pandas DF,我需要创建一个热图。我的数据看起来像这样,我想将年份放在列中,将天放在行中,然后将其与 Seaborn 一起使用以创建热图
我尝试了多种方法,但是当我选择 DF 时,我总是得到“不一致的形状”,所以有什么关于如何转换它的建议吗?
Year 和 Days 是这个系列的索引
2016年
Tuesday 4
Wednesady 6
.....
Run Code Online (Sandbox Code Playgroud)
2017年
Tuesday 4.4
Monday 3.5
....
Run Code Online (Sandbox Code Playgroud)
将 seaborn 导入为 sns ax = sns.heatmap(dayofweek)
我正在尝试生成类似于此图像的内容(图像取自此处)

我有文档的单词列表和标准化分数列表(假设为 0-1)。如何创建这样的热图(每个单词根据分数分配颜色)?我不知道从哪里开始,我不精通 matplotlib!
PS分数大多为0,是稀疏映射。
您好,我刚开始使用 Jupyter 笔记本、python、matplotlib、pandas 和 seaborn。我正在尝试使用 seaborn 中的 displot 函数绘制密度图。我也希望能够看到直方图,但我想看到密度而不是 y 轴上的“计数”。旧的 distplot 函数自动显示密度,我只是不知道如何用新的 displot 来设置它。任何帮助将不胜感激!