现在时间是:
当前位置:首 页 >> 数据可视>> 文章列表

Plotly 离线成图表的问题

作者:   发布时间:2016-03-02 14:32:35   浏览次数:9397

 

墙内生成在线的图表太慢了,不得不转向离线图表,以下三种方法:

1.采用cufflinks库,这个是以后的方向;

2.采用plotly的plot函数;

3.采用plotly的iplot函数;

区别是,1.如果采用了离线,文件名就没有毛用;2.即使没有文件名,也会自动创建名称;3.基本和1是相同的。

 

Ipython 预加载:

import pandas as pd

import numpy as np

import cufflinks as cf

cf.go_offline()

from plotly.offline import *

from plotly.graph_objs import *

init_notebook_mode()

# 擦,上面几行基本上把离线函数基本加载完了吧,除了转mpl为plotly暂时用不到

 

等Cufflinks的范例学习完了,好好看看

 

help(iplot)

Help on function iplot in module plotly.offline.offline:

iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', validate=True)
    Draw plotly graphs inside an IPython notebook without
    connecting to an external server.
    To save the chart to Plotly Cloud or Plotly Enterprise, use
    `plotly.plotly.iplot`.
    To embed an image of the chart, use `plotly.image.ishow`.
    
    figure_or_data -- a plotly.graph_objs.Figure or plotly.graph_objs.Data or
                      dict or list that describes a Plotly graph.
                      See https://plot.ly/python/ for examples of
                      graph descriptions.
    
    Keyword arguments:
    show_link (default=True) -- display a link in the bottom-right corner of
                                of the chart that will export the chart to
                                Plotly Cloud or Plotly Enterprise
    link_text (default='Export to plot.ly') -- the text of export link
    validate (default=True) -- validate that all of the keys in the figure
                               are valid? omit if your version of plotly.js
                               has become outdated with your version of
                               graph_reference.json or if you need to include
                               extra, unnecessary keys in your figure.
    
    Example:
    ```
    from plotly.offline import init_notebook_mode, iplot
    init_notebook_mode()
    
    iplot([{'x': [1, 2, 3], 'y': [5, 2, 7]}])
    ```
 

help(cf.iplot)

Help on function iplot in module cufflinks.plotlytools:

iplot(data_or_figure, validate=True, sharing=None, filename='', online=None, **kwargs)
    Plots a figure in IPython
    
    data_or_figure : figure
            Plotly figure to be charted
    validate : bool
            If True then all values are validated before 
            it is charted
    sharing : string
            Sets the sharing level permission
                    public - anyone can see this chart
                    private - only you can see this chart
                    secret - only people with the link can see the chart
    filename : string
            Name to be used to save the file in the server
    online : bool
            If True then charts are rendered in the server 
    
    Other Kwargs
    ============
    
            legend : bool
                    If False then the legend will not be shown

help(df.iplot)  
 

help(df.iplot)

Help on method _iplot in module cufflinks.plotlytools:

_iplot(self, data=None, layout=None, filename='', world_readable=None, kind='scatter', title='', xTitle='', yTitle='', zTitle='', theme=None, colors=None, colorscale=None, fill=False, width=None, mode='lines', symbol='dot', size=12, barmode='', sortbars=False, bargap=None, bargroupgap=None, bins=None, histnorm='', histfunc='count', orientation='v', boxpoints=False, annotations=None, keys=False, bestfit=False, bestfit_colors=None, categories='', x='', y='', z='', text='', gridcolor=None, zerolinecolor=None, margin=None, subplots=False, shape=None, asFrame=False, asDates=False, asFigure=False, asImage=False, dimensions=(1116, 587), asPlot=False, asUrl=False, online=None, **kwargs) method of pandas.core.frame.DataFrame instance
       Returns a plotly chart either as inline chart, image of Figure object
    
       Parameters:  # 对象Object
       -----------
           data : Data   # 数据格式为DataFrame,可以由Numpy或者Pandas生成
               Plotly Data Object.
               If not entered then the Data object will be automatically
               generated from the DataFrame.
           layout : Layout  # 区别在于填充图表的显示格式,单线条就木有用
               Plotly layout Object
               If not entered then the Layout objet will be automatically
               generated from the DataFrame.
           filename : string # 文件名,如果采用离线模式,这个参数就是缺省项了,在plotly中的plot则是html本地存储路径,cufflinks则不能本地存储html
               Filename to be saved as in plotly account
           world_readable : bool # 生成到plotly网站数据库的图表能否被别人看到,可在用账号登录进行更多设置
               If False then it will be saved as a private file
           kind : string # 这么多格式的图牛掰啊,可以参照plotly的数据格式来提交data,回头测试一下cufflinks
               Kind of chart
                   scatter
                   bar
                   box
                   spread
                   ratio
                   heatmap
                   surface
                   histogram
                   bubble
                   bubble3d
                   scatter3d
           title : string   # 图表的名字
               Chart Title
           xTitle : string  # x坐标的标题
               X Axis Title
           yTitle : string # y坐标的标题
               Y Axis Title
                   zTitle : string
           zTitle : string  # z坐标的标题
               Z Axis Title
               Applicable only for 3d charts
           theme : string  # 几种显示的主题,觉得white不错
               Layout Theme
                   solar
                   pearl
                   white
               see cufflinks.getThemes() for all
               available themes
           colors : list or dict # 自己定义颜色'r'或者rgba[]
               {key:color} to specify the color for each column
               [colors] to use the colors in the defined order
           colorscale : str  # 曹操,那么多格式竟然不会用
               Color scale name
               If the color name is preceded by a minus (-)
               then the scale is inversed
               Only valid if 'colors' is null
               See cufflinks.colors.scales() for available scales
           fill : bool  # 是否填充
               Filled Traces
           width : int # 线条宽度
               Line width
           mode : string # 散点图的模式
               Plotting mode for scatter trace
                   lines
                   markers
                   lines+markers
                   lines+text
                   markers+text
                   lines+markers+text
           symbol : string  # 标记,在有marker的时候可用
               The symbol that is drawn on the plot for each marker
               Valid only when mode includes markers
                   dot
                   cross
                   diamond
                   square
                   triangle-down
                   triangle-left
                   triangle-right
                   triangle-up
                   x
           size : string or int # 标点marke的大小
               Size of marker
               Valid only if marker in mode
           barmode : string  # bars的模式,只有在kind='bar'下可用
               Mode when displaying bars
                   group
                   stack
                   overlay
               * Only valid when kind='bar'
           sortbars : bool # 按照降续排bars
               Sort bars in descending order
               * Only valid when kind='bar'
           bargap : float # bars的间隙宽度
               Sets the gap between bars
                   [0,1)
               * Only valid when kind is 'histogram' or 'bar'
           bargroupgap : float # bars群内部间距
               Set the gap between groups
                   [0,1)
               * Only valid when kind is 'histogram' or 'bar'
           bins : int 
               Specifies the number of bins # 直方图的*数量
               * Only valid when kind='histogram'
           histnorm : string
                   '' (frequency)
                   percent
                   probability
                   density
                   probability density
               Sets the type of normalization for an histogram trace. By default
               the height of each bar displays the frequency of occurrence, i.e.,
               the number of times this value was found in the
               corresponding bin. If set to 'percent', the height of each bar
               displays the percentage of total occurrences found within the
               corresponding bin. If set to 'probability', the height of each bar
               displays the probability that an event will fall into the
               corresponding bin. If set to 'density', the height of each bar is
               equal to the number of occurrences in a bin divided by the size of
               the bin interval such that summing the area of all bins will yield
               the total number of occurrences. If set to 'probability density',
               the height of each bar is equal to the number of probability that an
               event will fall into the corresponding bin divided by the size of
               the bin interval such that summing the area of all bins will yield
               1.
			   * Only valid when kind='histogram'
			   '''
			   
			    设置直方图跟踪的类型。默认
				每个栏的高度显示发生的频率,即,
				在该值被发现的时间的次数
				对应的仓。如果设置为“%”,每个栏的高度
				显示在该范围内发现的总发生的百分比
				对应的仓。如果设置为“概率”,每个栏的高度
				显示事件将陷入的概率
				对应的仓。如果设置为“密度”,每个栏的高度是
				等于在一个大小的容器中出现的数目相等
				本区间的所有箱的面积求和将得到
				总发生次数。如果设置为“概率密度”,
				每个栏的高度等于一个概率的数目
				事件将分为相应的大小的大小
				本区间的所有箱的面积求和将得到
1。
			   '''
               
           histfunc : string # 直方图的函数
                   count
                   sum
                   avg
                   min
                   max
              Sets the binning function used for an histogram trace.
               * Only valid when kind='histogram'
           orientation : string # 方向:水平或垂直
                   h
                   v
               Sets the orientation of the bars. If set to 'v', the length of each
    |          bar will run vertically. If set to 'h', the length of each bar will
    |          run horizontally
               * Only valid when kind is 'histogram','bar' or 'box'
           boxpoints : string # 箱型图
               Displays data points in a box plot
                   outliers
                   all
                   suspectedoutliers
                   False
           annotations : dictionary # 注释,字典型
               Dictionary of annotations
               {x_point : text}
           keys : list of columns # 列表单
               List of columns to chart.
               Also can be usded for custom sorting.
           bestfit : boolean or list # bestfit最佳耦合,逻辑或列表
               If True then a best fit line will be generated for
               all columns.
               If list then a best fit line will be generated for
               each key on the list.
           bestfit_colors : list or dict # 定义每列的颜色
               {key:color} to specify the color for each column
               [colors] to use the colors in the defined order
           categories : string # 分类
               Name of the column that contains the categories
           x : string  #坐标名
               Name of the column that contains the x axis values
           y : string
               Name of the column that contains the y axis values
           z : string
               Name of the column that contains the z axis values
           text : string
               Name of the column that contains the text values
           gridcolor : string  # 网格颜色
               Grid color
           zerolinecolor : string  # 0线颜色,轴
               Zero line color
           margin : dict or tuple # 边缘位置
               Dictionary (l,r,b,t) or
               Tuple containing the left,
               right, bottom and top margins
           subplots : bool # 显示模式
               If true then each trace is placed in
               subplot layout
           shape : (rows,cols)
               Tuple indicating the size of rows and columns # 行列大小
               If omitted then the layout is automatically set
               * Only valid when subplots=True
           asFrame : bool # Pandas form (Series)序列
               If true then the data component of Figure will
               be of Pandas form (Series) otherwise they will
               be index values
           asDates : bool # 时间序列
               If true it truncates times from a DatetimeIndex
           asFigure : bool # 参数流
               If True returns plotly Figure
           asImage : bool # 图像
               If True it returns Image
               * Only valid when asImage=True
           dimensions : tuple(int,int) # 尺寸
               Dimensions for image
                   (width,height)
           asPlot : bool # 从浏览器显示
               If True the chart opens in browser
           asUrl : bool # 返回地址不显示
               If True the chart url is returned. No chart is displayed.
           online : bool  # 墙内必须离线
               If True then the chart is rendered on the server
               even when running in offline mode.
 
 






上一篇:没有了    下一篇:没有了

Copyright ©2019    易一网络科技|www.yeayee.com All Right Reserved.

技术支持:自助建站 | 领地网站建设 |短信接口 |燕窝 版权所有 © 2005-2019 lingw.net.粤ICP备16125321号 -5