小编Eri*_*man的帖子

Seaborn Barplot上的标签轴

我正在尝试使用我自己的标签来制作Seaborn条形图,其代码如下:

import pandas as pd
import seaborn as sns

fake = pd.DataFrame({'cat': ['red', 'green', 'blue'], 'val': [1, 2, 3]})
fig = sns.barplot(x = 'val', y = 'cat', 
                  data = fake, 
                  color = 'black')
fig.set_axis_labels('Colors', 'Values')
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

但是,我得到一个错误:

AttributeError: 'AxesSubplot' object has no attribute 'set_axis_labels'
Run Code Online (Sandbox Code Playgroud)

是什么赋予了?

python matplotlib seaborn

95
推荐指数
4
解决办法
15万
查看次数

使用Seaborn的FacetGrid自定义注释

我正在尝试使用Python中的Seaborn模块自定义一些数字,但我没有运气创建自定义标签或注释.我有一些代码生成下图:

plot = sns.FacetGrid(data = data, col = 'bot', margin_titles = True).set_titles('Human', 'Bot')
bins = np.linspace(0, 2000, 15)
plot = plot.map(plt.hist, 'friends_count', color = 'black', lw = 0, bins = bins)
plot.set_axis_labels('Number Following', 'Count')
sns.despine(left = True, bottom = True)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我想做两件事:1.用有意义的文本替换默认因子标签,例如'bot = 0.0',以及2.在每个类别的平均数后面绘制垂直线.

这是一个自包含的例子:

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

fake = pd.DataFrame({'val': [1, 2, 2, 3, 3, 2, 1, 1, 2, 3], 'group': [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]}) …
Run Code Online (Sandbox Code Playgroud)

python matplotlib seaborn

11
推荐指数
1
解决办法
7651
查看次数

pandoc文档转换失败,错误127

我不知道如何制作一个可重现的例子,但我很想知道是否有其他人遇到过这个问题.我在运行Ubuntu的EC2实例上通过闪亮的服务器托管了一个R Markdown文件.一切都运行良好几天,现在突然我尝试在浏览器中查看文档时出现以下错误:

pandoc document conversion failed with error 127
Run Code Online (Sandbox Code Playgroud)

我没有转换为pdf,没有推动任何更改,并且几小时前它正在运行.我在网上找不到关于这个错误代码的任何内容,所以我不知道如何调试这个问题.有人曾经发生过这种事吗?

r amazon-ec2 pandoc r-markdown shiny-server

8
推荐指数
2
解决办法
5667
查看次数

如何用iGraph挖掘R中的图案

我正在尝试使用该软件包在R中挖掘3节点图案igraph.我想检索图中每个顶点的图案数量,这从graph.motifs()函数中看不出来.

因此,对于示例图:

testGraph = barabasi.game(10, 
m = 5,
power = 2, 
out.pref = TRUE,
zero.appeal = 0.5,
directed = TRUE)
Run Code Online (Sandbox Code Playgroud)

我可以graph.motifs()用来计算整个图中每个3节点图案的总数:

graph.motifs(testGraph, 
size = 3)
Run Code Online (Sandbox Code Playgroud)

[1] 0 0 26 0 16 0 2 58 0 0 0 0 0 0 0 0

但我想知道个别顶点参与.那么,顶点1参与了多少个图案(以及什么类型)?有人知道一个简单的方法吗?

r graph igraph

7
推荐指数
2
解决办法
2830
查看次数

索引到数据帧时如何诱导R"忽略"NA?

我有一个包含一些NA的数据帧,当我索引它时,我希望R忽略该列中的NA.

fake = data.frame(id = 1:5,
                  color = c('red', NA, NA, 'blue', 'blue'),
                  value = rnorm(5))

sub = fake[fake$color != 'red', ]

     id color      value
NA   NA  <NA>         NA
NA.1 NA  <NA>         NA
4     4  blue -0.3227421
5     5  blue -1.0196561
Run Code Online (Sandbox Code Playgroud)

我想要的数据帧是:

  id color      value
2  2  <NA>  0.2761862
3  3  <NA>  1.0029380
4  4  blue -0.3227421
5  5  blue -1.0196561
Run Code Online (Sandbox Code Playgroud)

但无论出于何种原因,当遇到"颜色"中的NA时,R NAs会排出整个行.我已经用'na.exclude','na.pass'等进行了讨论,但是还没有找到一个干净的方法来做到这一点.

r

5
推荐指数
1
解决办法
816
查看次数

如何使用geom_tile在ggplot2中创建相对tile大小?

我正在尝试对各组颜色及其补充进行可视化.我想用geom_tile将它们并排放置.我的问题是一些目标颜色有多个补充,所以我需要能够在颜色之间均匀地分割补色块.

我的测试数据集是这样的:

test_pair = data.frame(pair_number = c(1, 1, 2, 2, 3, 3, 3), 
                       color = c('#5f75e6', '#e6d05f', '#5f75e6', '#5fb9e6', '#5f75e6', '#b9e65f', '#e68d5f'),
                       group = c('target', 'comp', 'target', 'comp', 'target', 'comp', 'comp'),
                       bin_width = c(1, 1, 1, 1, 1, 0.5, 0.5))
Run Code Online (Sandbox Code Playgroud)

我的情节代码:

ggplot(test_pair, aes(x = factor(group), y = factor(pair_number), width = bin_width)) +
       geom_tile(aes(fill = color)) +
       scale_fill_identity() +
       scale_x_discrete('', expand = c(0, 0)) +
       scale_y_discrete('', expand = c(0, 0)) + 
       theme_bw() +
       theme(line = element_blank(),
            panel.grid.major = element_blank(),
            panel.grid.minor = …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

5
推荐指数
1
解决办法
2076
查看次数