小编Ian*_*son的帖子

第二个y轴时间序列seaborn

使用数据帧seaborn可以与seaborn绘制说column1sns.tsplot(data=df.column1, color="g").我们怎样才能在seaborn中绘制两个y轴的时间序列?

python seaborn

16
推荐指数
3
解决办法
2万
查看次数

熊猫DataFrame的多列并排的boxplot

一年的样本数据:

import pandas as pd
import numpy.random as rnd
import seaborn as sns
n = 365
df = pd.DataFrame(data = {"A":rnd.randn(n), "B":rnd.randn(n)+1},
                  index=pd.date_range(start="2017-01-01", periods=n, freq="D"))
Run Code Online (Sandbox Code Playgroud)

我想将这些数据并排分组,按月分组(即每月两个盒子,一个盒子A和一个盒子B).对于单个列sns.boxplot(df.index.month, df["A"])工作正常.但是,sns.boxplot(df.index.month, df[["A", "B"]])抛出一个错误(ValueError: cannot copy sequence with size 2 to array axis with dimension 365).通过index(pd.melt(df, id_vars=df.index, value_vars=["A", "B"], var_name="column"))熔化数据以使用seaborn的hue属性作为变通方法也不起作用(TypeError: unhashable type: 'DatetimeIndex').

(如果使用普通的matplotlib更容易,解决方案不一定需要使用seaborn.)

/编辑:我找到了一个基本上可以产生我想要的解决方法.但是,一旦DataFrame包含的变量多于我想绘制的变量,就会变得有些尴尬.所以,如果有更优雅/直接的方式,请分享!

df_stacked = df.stack().reset_index()
df_stacked.columns = ["date", "vars", "vals"]
df_stacked.index = df_stacked["date"]
sns.boxplot(x=df_stacked.index.month, y="vals", hue="vars", …
Run Code Online (Sandbox Code Playgroud)

python plot boxplot pandas seaborn

10
推荐指数
2
解决办法
4384
查看次数

我可以在Seaborn的x轴上绘制日期时间的线性回归吗?

我的DataFrame对象看起来像

            amount
date    
2014-01-06  1
2014-01-07  1
2014-01-08  4
2014-01-09  1
2014-01-14  1
Run Code Online (Sandbox Code Playgroud)

我想要一种散布图,其中沿x轴的时间为时间,沿y的量为时间,并通过数据线来引导观察者的眼睛。如果我使用panadas图,df.plot(style="o")那是不太正确的,因为那条线不在那。我想要类似这里的示例。

python matplotlib dataframe pandas seaborn

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

Langchain - 无法解决矢量存储的动态过滤问题

我正在使用Langchainversion 0.218,并且想知道是否有人能够在运行时动态过滤种子向量库?例如当由代理运行时。

我的动机是将这个动态过滤器放入对话检索 QA 链中,在其中我使用filename从对话输入中提取的内容来过滤检索器并检索其所有块(使用映射器文件k设置为属于search_kwargs中文件名的块的计数)。

我可以手动过滤种子向量库(如 Chroma) ,例如:

from langchain.chains import ConversationalRetrievalChain
from langchain.memory import ConversationBufferMemory

# init a vectorstore and seed documents
vectorstore = Chroma.from_documents(..)

# 'somehow' I get hands on the filename from user input or chat history
found_filename = "report.pdf"

# filter using a search arg, such as 'filename' provided in the metadata of all chunks
file_chunk_mapper = {"report.pdf" : ["chunk1", "chunk2", ... ] …
Run Code Online (Sandbox Code Playgroud)

information-retrieval artificial-intelligence chaining large-language-model py-langchain

7
推荐指数
0
解决办法
905
查看次数

奇怪的熊猫pivot_table aggfunc / values参数

我有这个数据集:

np.random.seed(0)

test = pd.DataFrame({
    'a' : np.random.randint(0, 10, size=(10,)),
    'b' : np.random.randint(0, 10, size=(10,)),
    'c' : np.random.randint(0, 10, size=(10,)),
    'd' : np.random.randint(0, 10, size=(10,)),
})

print(test)

   a  b  c  d
0  5  7  5  2
1  0  6  9  3
2  3  8  8  8
3  3  8  9  1
4  7  1  4  3
5  9  6  3  3
6  3  7  0  3
7  5  7  3  7
8  2  8  5  0
9  4  1  0 …
Run Code Online (Sandbox Code Playgroud)

aggregate pivot-table pandas

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

Seaborn 热图按行颜色

我有一个网络图。

网络

每个节点都是一个案例,每条边都是一个 CPT。

我曾经community.best_partition将图表分成四个社区(用颜色标记)。

为了更好地可视化我使用的每个社区中共享的 CPT 和案例量plt.subplots,并sns.heatmap创建了四个社区之间具有相似匹配颜色的热图。

热图

生成热图的代码:

fig, axs = plt.subplots(nrows=4, figsize=(16,8), sharex=True)

cmaps = ['Blues', 'Oranges', 'Greens', 'Reds']

comms = range(4)

for ax, cmap, comm in zip(axs, cmaps, comms):
    sns.heatmap(
        data=_.loc[[comm]],
        ax=ax,
        cmap=cmap,
        annot=True,
        annot_kws={
            'fontsize' : 12
        },
        fmt='g',
        cbar=False,
        robust=True,
    )

    ax.set_ylabel('Community')

    ax.set_xlabel('');
Run Code Online (Sandbox Code Playgroud)

问题

有没有办法按sns.heatmap行(在本例中为社区)指定颜色,而无需创建 4 个单独的热图?

这是一些示例数据:

cpt   52320  52353  52310  49568  50432  52234  52317  50435  52354  52332
comm                                                                      
0       NaN    3.0    NaN    1.0    1.0    NaN    2.0 …
Run Code Online (Sandbox Code Playgroud)

python matplotlib heatmap seaborn

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