【问题标题】:plot pandas dataframe in jupyter with voila用 voila 在 jupyter 中绘制 pandas 数据框
【发布时间】:2020-05-07 05:17:20
【问题描述】:

情况: 我有一个 jupyter 笔记本,可以在其中创建和操作 DataFrame。

在某个时候我有:

mydf = conceptsdf['date'].groupby([conceptsdf['date'].dt.year, conceptsdf['date'].dt.month]).agg('count')
mydf.plot(kind="bar")

基本上我每月汇总发生次数。该图在笔记本中按预期正确显示在以下行:

<matplotlib.axes._subplots.AxesSubplot at 0x283dc381148>

问题: 我已经安装了瞧,当我点击它时一切正常,但是在瞧网络结果中,情节没有出现,而只有一行:

AxesSubplot(0.125,0.11;0.775x0.77)

任何想法如何获得输出中的图也是如此。

【问题讨论】:

    标签: python pandas plot jupyter-notebook


    【解决方案1】:

    由于您发布的代码有限,我猜您没有使用%matplotlib widget

    使用有效的熊猫图的示例(请参阅下面的链接以获取演示笔记本):

    %matplotlib widget
    import pandas as pd
    iris = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv')
    iris.plot.hist();
    

    正如 herehere 所记录的那样,“在后台,pandas 使用 matplotlib 库绘制图形。”因此,这种方法通常适用于 matplotlib。

    我笔记本中单元格中的示例工作 matplotlib 图(链接如下):

    %matplotlib widget
    import matplotlib.pyplot
    import matplotlib.pyplot as plt
    import numpy as np
    fig = matplotlib.pyplot.figure()
    a = matplotlib.pyplot.imshow(np.random.randn(100, 100))
    a.figure
    

    我有一些基于我之前收集的代码和this discussion here 的示例。对于 Pandas 数据框绘图,请转到 https://github.com/fomightez/communication_voila/ 并单击文本“以作为笔记本的 Pandas 数据框绘图演示开始”旁边的徽章。启动后,您可以运行所有单元格,然后单击顶部工具栏中的Voila 按钮。
    对于 matplotlib 示例页面,请转到 https://github.com/fomightez/communication_voila/ 并单击文本“以 matplotlib 演示作为笔记本开始”旁边的徽章。启动后,您可以运行所有单元格,然后单击顶部工具栏中的Voila 按钮。

    那些笔记本和引用here 的“示例”可能为解决您的问题提供了良好的基础。

    【讨论】:

    • 你说得对,我只是在使用熊猫情节。我会试试你的代码。
    • 我现在添加了一个熊猫数据框绘图示例。
    猜你喜欢
    • 2015-09-29
    • 1970-01-01
    • 2015-08-03
    • 2017-02-21
    • 2020-04-24
    • 1970-01-01
    • 2020-05-17
    • 1970-01-01
    • 2017-03-27
    相关资源
    最近更新 更多