我的数据如下:
m=pd.DataFrame({'model':['1','1','2','2','13','13'],'rate':randn(6)},index=['0', '0','1','1','2','2'])
Run Code Online (Sandbox Code Playgroud)
我希望在[1,2,13]中排序因子图的x轴,但默认值为[1,13,2].
有谁知道如何改变它?
更新:我想我已经通过以下方式解决了这个问题,但也许有一种更好的方法可以使用索引来做到这一点?
sns.factorplot('model','rate',data=m,kind="bar",x_order=['1','2','13'])
Run Code Online (Sandbox Code Playgroud) Seaborn允许定义包含多种颜色的调色板,对于包含多行的图表非常有用.但是,当将调色板设置为具有多种颜色的调色板时,仅使用前六种颜色,之后颜色会再循环,从而难以区分线条.这可以通过显式调用调色板来覆盖,但这不方便.当定义超过6个时,有没有办法强制Seaborn当前调色板不回收颜色?
例:
from matplotlib import pyplot as plt
import pandas as pd
import seaborn as sb
# Define a palette with 8 colors
cmap = sb.blend_palette(["firebrick", "palegreen"], 8)
sb.palplot(cmap)
Run Code Online (Sandbox Code Playgroud)

# Set the current palette to this; only 6 colors are used
sb.set_palette(cmap)
sb.palplot(sb.color_palette() )
Run Code Online (Sandbox Code Playgroud)

df = pd.DataFrame({x:[x*10, x*10+5, x*10+10] for x in range(8)})
fig, (ax1, ax2) = plt.subplots(2,1,figsize=(4,6))
# Using the current palette, colors repeat
df.plot(ax=ax1)
ax1.legend(bbox_to_anchor=(1.2, 1))
# using the palette that defined the current palette, colors don't repeat …Run Code Online (Sandbox Code Playgroud) 我从这里稍微修改了这段代码:
import seaborn as sns
sns.set(style="darkgrid")
tips = sns.load_dataset("tips")
color = sns.color_palette()[5]
g = sns.jointplot("total_bill", "tip", data=tips, kind="reg", stat_func=None,
xlim=(0, 60), ylim=(0, 12), color='k', size=7)
g.set_axis_labels('total bill', 'tip', fontsize=16)
Run Code Online (Sandbox Code Playgroud)
我得到了一个漂亮的情节 - 但是,对于我的情况,我需要能够改变每个点的颜色和格式.
我使用的关键字尝试,marker,style,和fmt,但我得到的错误TypeError: jointplot() got an unexpected keyword argument.
这样做的正确方法是什么?我想避免sns.JointGrid手动调用和绘制数据和边际分布.
如何更改seaborn中我的lmplot的数字大小?
这是我目前的代码,但显然figsize不被接受.
sns.lmplot(x="x", y="y", hue="category", data=df,fit_reg=False,
markers=["o", "x"], palette="Set1",figsize=(7,7));
Run Code Online (Sandbox Code Playgroud)
谢谢
我用
sns.distplot
Run Code Online (Sandbox Code Playgroud)
绘制单变量的观测分布.不过,我不仅需要图表,还需要数据点.如何从matplotlib轴获取数据点(由distplot返回)?
我正在努力按照pabas中的数据帧按照seaborn的热图(或matplotlib)的正确格式来制作热图.
我当前的数据框(称为data_yule)是:
Unnamed: 0 SymmetricDivision test MutProb value
3 3 1.0 sackin_yule 0.100 -4.180864
8 8 1.0 sackin_yule 0.050 -9.175349
13 13 1.0 sackin_yule 0.010 -11.408114
18 18 1.0 sackin_yule 0.005 -10.502450
23 23 1.0 sackin_yule 0.001 -8.027475
28 28 0.8 sackin_yule 0.100 -0.722602
33 33 0.8 sackin_yule 0.050 -6.996394
38 38 0.8 sackin_yule 0.010 -10.536340
43 43 0.8 sackin_yule 0.005 -9.544065
48 48 0.8 sackin_yule 0.001 -7.196407
53 53 0.6 sackin_yule 0.100 -0.392256
58 58 0.6 sackin_yule 0.050 -6.621639 …Run Code Online (Sandbox Code Playgroud) Seaborn可以选择创建漂亮的调色板.我希望使用这些调色板生成颜色,这些颜色可以在地图中很好地协同工作,其中根据某些属性对国家进行着色.以下代码从浅到深产生8种紫色阴影.另请注意,指定颜色数量的能力是必需的,因此我不能只使用定义颜色的固定调色板.
import seaborn as sns
num_shades = 8
sns.palplot(sns.cubehelix_palette(num_shades))
Run Code Online (Sandbox Code Playgroud)
如果我运行相同但在这样的列表中:
color_list = sns.cubehelix_palette(num_shades)
Run Code Online (Sandbox Code Playgroud)
你得到:
[[0.9312692223325372, 0.8201921796082118, 0.7971480974663592], ...
Run Code Online (Sandbox Code Playgroud)
这些显然不是RGB值,这是我需要的.
1)这些颜色是什么格式?2)如何转换为RGB或6位数代码?
我试过很长一段时间没找到答案.我看过这里和其他seaborn文档:
https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.set_color_codes.html
我可以使用以下方法从RGB转换为6位数代码:
但我被困在如何直接或通过获取RGB值.任何帮助,将不胜感激.
我有以下代码来创建Seaborn条带图.我很难弄清楚如何增加绘图中出现的图例的字体大小.
g=sns.stripplot(x="Market", y="Rate", hue="Group",data=myBenchmarkData, jitter=True, size=12, alpha=0.5)
g.axes.set_title("4* Rate Market and by Hotel Groups for Year 2016",fontsize=25)
g.set_xlabel("Market",fontsize=20)
g.set_ylabel("Rate (in EUR)",fontsize=20)
g.tick_params(labelsize=15)
plt.savefig ('benchmark1.png')
Run Code Online (Sandbox Code Playgroud)
我的x轴和y轴标签字体大小没问题,但我的绘图中图例的字体大小很小.怎么改呢?
使用seaborn的文档代码生成一个lineplot返回一个AttributeError:'module'对象没有属性'lineplot'.我已更新seaborn并重新导入模块并再次尝试,没有运气.lineplot是否已退役,或者还有其他事情发生了吗?
import seaborn as sns; sns.set()
import matplotlib.pyplot as plt
fmri = sns.load_dataset("fmri")
ax = sns.lineplot(x="timepoint", y="signal", data=fmri)
Run Code Online (Sandbox Code Playgroud) 我正在寻找一种seaboarn通过指定fmt关键字在的热图上将“0.0045”显示为“0.45%”的方法:
sns.heatmap(data, annot=True, fmt='??')
Run Code Online (Sandbox Code Playgroud)
但是,我没有找到要使用的格式列表。在不同的示例之间搜索,我看到了“d”、“.2g”、“.1f”、“.1f%”。但不清楚我们在这里假设的约定是什么。
这是假设人们对格式格式有共同的理解吗?或者这出现在我错过的文档页面上?