如何更改条形图的颜色?

时间:2019-07-15 06:12:58

标签: python matplotlib

我的条形图设置为默认的蓝色,因此我想将其更改为橙色。我需要对代码进行哪些更改,以便可以更改颜色?

这是我的代码:

trace2 =go.Bar(
x=['China','Hong Kong SAR','India','Indonesia','Japan','Malaysia','Phillpines','South Korea','Taiwan','Thailand','Vietnam'],
y=[4622347,1368789,2321576,5284928,2051699,2858926,1598839,114774,812080,1229608,1034688])

data = [trace2]
layout= dict(title='Total arrival counts from 2013 to 2015 for countries in Asia region by air', yaxis =dict(title='Arrival counts'),xaxis =dict(title='Countries'))
flg= go.Figure(data=data, layout=layout)
iplot(flg)

1 个答案:

答案 0 :(得分:0)

您可以将颜色作为RGBA传递给Bar调用:

go.Bar(x, y, color=(0.2, 0.4, 0.6, 0.6))

对于Plotly,您必须使用:

go.Bar(x, y, marker=dict(
        color='rgb(204,204,204)'))