【问题标题】:How to create plotly offline chart from array?如何从数组创建绘图离线图表?
【发布时间】:2017-03-26 11:43:34
【问题描述】:

我有一个熊猫数据集,我对 regionstotal_count 的两列感兴趣。

def print_row(regionCount):
    print regionCount['region']
    print regionCount['total_count']
regionCount.apply(print_row, axis = 1)   

输出如下:

Fribourg
376
Vallis
608
...

在整个数据集中,有 20 个区域及其对应的 total_count。我想要描述条形列的名称和作为条形高度的数字。如何构建一个图表,从名为 regionCount 的列表中获取这些值?

在下面的代码中,我想用foodserviceenvironment 以及数字:3.44.24.3 替换为regionCount['region'][0...end_of_regionCount] 和@987654334 @分别。

plotly.offline.plot({
"data": [
     plotly.graph_objs.Bar(x=['food','service','environment'],y=  
[3.4,4.2,4.3])

],

 'layout': {'title': 'distribution', 
       'font': dict(family='Arial', size=16)}},
         auto_open=True, image = 'png', image_filename='plot_image',
         output_type='file', image_width=800, image_height=600, filename='temp-plot.html', validate=False
)

【问题讨论】:

标签: python list pandas charts plotly


【解决方案1】:

不确定我的问题是否正确,但您可以使用 df.region 作为 x 值,使用 df.total_count 作为 y 值,无需任何修改。

import pandas as pd
import plotly

df = pd.DataFrame({'region': ['Fribourg', 'Vallis', 'Geneva'], 
                   'total_count': [376, 608, 555]})

plotly.offline.plot({"data": [plotly.graph_objs.Bar(x=df.region,
                              y=df.total_count)]})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-25
    相关资源
    最近更新 更多