python-plotly-boxplot为什么不在图表上显示最大值和最小值

时间:2016-07-22 19:52:02

标签: python matplotlib plot boxplot plotly

这是我的数据:[0,45,47,46,47,47,43,100]。 图片看起来像这样: https://plot.ly/~zfrancica/8/

我想要这样的照片:https://plot.ly/~zfrancica/9/ ([0,45,47,46,100]的出局图片)

我想要一个固定的0最小值和100最大值。(可能这不是正确的方框图,但我想确定最小值和最大值。)我应该怎么做?

(如果情节不能这样做,matplotlib绘图代码也可以。) 我的代码:

import plotly.plotly as py
import plotly.graph_objs as go

def box_plot(**kwargs):
    print kwargs
    num = len(kwargs['circum'])
    #WornPercentage = go.Box(x=kwargs['circum'])
    #data = [WornPercentage]

    #py.iplot(data)

    data = [
        go.Box(
            x=kwargs['circum'],
            boxpoints='all',
            jitter=0.3,
            pointpos=-1.8
        )
    ]
    py.iplot(data)



process_dict={'circum':[0, 45, 47, 46, 47,47,43,100]}
box_plot(**process_dict)

1 个答案:

答案 0 :(得分:0)

凭据

对于那些不知道如何永久保存凭证的人;

import plotly.tools as tls
tls.set_credentials_file(username='username', api_key='api-key')

假设您已保存凭据;

A - 简单解决方案

对于单个一维数据;

import plotly.plotly as py
import plotly.graph_objs as go

trace0 = go.Box(
    y=[0, 45, 47, 46, 47, 47, 43, 100], # Data provided
    name = 'Provided Data Chart',
    marker = dict(
        color = 'rgb(0, 0, 255)'        # Blue : #0000FF
    )
)

data = [trace0]
py.plot(data)                           # Using plot instead of iplot

A - 输出

enter image description here

B - 使用布局

您还可以查看这个以获得更好的布局,您可以使用range选项,因为autorange设置为False;

import plotly.plotly as py
import plotly.graph_objs as go
from plotly.graph_objs import Layout
from plotly.graph_objs import Font
from plotly.graph_objs import YAxis
from plotly.graph_objs import Figure

trace0 = go.Box(
    y=[0, 45, 47, 46, 47, 47, 43, 100], # Data provided
    name = 'Provided Data Chart',
    marker = dict(
        color = 'rgb(0, 0, 255)'        # Blue : #00FF00
    )
)

data = [trace0]

layout = Layout(
    autosize=True,
    font=Font(
        family='"Droid Sans", sans-serif'
    ),
    height=638,
    title='Plotly Box Demo',
    width=1002,
    yaxis=YAxis(
        autorange=False,                # Autorange set to False
        range=[0, 100],                 # Custom Range
        title='Y units',                # To be changed, units
        type='linear'                   # Use 'log' for appropriate data
    )
)

fig = Figure(data=data, layout=layout)

plot_url = py.plot(fig)                 # Using plot instead of iplot

B - 输出

enter image description here

希望它有所帮助。