我正在 Plotly 中創建一個圖表作為 Django 專案的一部分,我遇到的問題是,當我只有一個值時,條形圖的大小非常大,顯然,只要我有多個專案,條形圖開始看起來不錯,但是什么時候只有一個值真的很難看,有誰知道如何解決這個問題?
def get_leads_data(request):
c = Profile.objects.get(user=request.user)
qs = Leads.objects.filter(
agent_id=c,status='Open')
df = read_frame(qs)
graphs = []
graphs.append(go.Bar(
x=df['company'],
y=df['expected_revenue'],
name='Estimated Revenue'
))
layout={
'title': 'Estimated Revenue by Company',
'xaxis_title':'Company',
'yaxis_title':'Revenue',
'height':500,
'width':640,
}
plot_div = plot({'data': graphs, 'layout': layout},
output_type='div')
return render(request,'account/plot.html',{'plot_div':plot_div})

uj5u.com熱心網友回復:
你可以設定width屬性go.Bar
屬性寬度
設定誤差線兩端交叉線的寬度(以像素為單位)。
'width' 屬性是一個數字,可以指定為: [0, inf] 區間內的整數或浮點數
示例用法
import plotly.graph_objects as go
fig = go.Figure(go.Bar(x=[1], y=[200], width=0.2))
fig.show()
由于您指定了當只有一個條時不喜歡寬度,因此您可以有條件地將值傳遞給width屬性。因此,如果您的資料的行數等于 1,您可以將寬度更改為較小的寬度,否則您不會傳入任何內容并將其保留為情節。
uj5u.com熱心網友回復:
Awenser 的問題:
def plot_deals_data(qs): df = read_frame(qs)
graphs = []
graphs.append(go.Bar(
x=df['company'],
y=df['revenue'],
name='Estimated Revenue',
marker=dict(color='#008375'),
width=0.2,
))
layout = {
'title': 'Revenue by Company',
'title_xanchor':'center',
'title_yanchor':'top',
'title_y':0.9,
'title_x':0.5,
'xaxis_title': 'Company',
'yaxis_title': 'Actual Revenue',
'height': 600,
'width': 740,
'font_family':'Muli',
'font_color':'#008375',
'font_size': 16
}
plot_div = plot({'data': graphs, 'layout': layout},
output_type='div',include_plotlyjs=False,
show_link=False,link_text="")
return plot_div
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/360208.html
下一篇:檢查電子郵件是否已存在于資料庫中
