我花了几个小时努力设计我的饼图标题。本质上,我想增加字体大小并使其加粗。无论是从对象参数还是update_layout我都没有找到处理此问题的正确方法。
还有什么方法可以增加标签的大小并删除图例吗?
多谢您的支持!
这是我的代码:
pie_chart = px.pie(
data_frame=ca_sum_df,
values='Last month sales',
names='Commercial network',
color='Commercial network',
#color_discrete_sequence=["red","green"],
color_discrete_map={'VIP customers':"#d28c00","Standard Retail Partner":'#d9d9d9'},
hover_data=['Commercial network','Last month sales'],
title="TURNOVER SPLIT-DOWN",
template='ggplot2',
width=800,
height=600,
hole=0.5
)
pie_chart.update_layout(
# Add annotations in the center of the donut pies.
annotations=[dict(text=val_ca_sum, x=0.50, y=0.5, font_size=30, showarrow=False)],
font=dict(size=25)
)
pie_chart.write_image("images/Page1_TurnoverSplitDown.png")
Run Code Online (Sandbox Code Playgroud) 我有一个使用的甘特图/时间线图,并想像离散颜色plotly.express教程中那样指定条形的颜色,但我被卡住了。无论是否使用或参数,输出条都是单色的:color_discrete_mapcolor_discrete_sequence
正如上图所示,条形颜色始终是单色的。如果我只是将color="Resource"条形根据资源设置为多种颜色,这就是我想要的。不幸的是,由于以后的一些使用,我需要准确指定条形的颜色。
这是我用来生成上面图片的代码:
import pandas as pd
import plotly.express as px
from io import StringIO
import numpy as np
csv = """Task,Start,Finish,Workstation,Resource
1,1970-01-01 01:00:00.000,1970-01-01 01:00:05.400,1,ABL
2,1970-01-01 01:00:00.000,1970-01-01 01:00:01.300,2,ABS
3,1970-01-01 01:00:00.000,1970-01-01 01:00:01.000,3,ABU
4,1970-01-01 01:00:00.000,1970-01-01 01:00:02.000,4,ACC
5,1970-01-01 01:00:02.000,1970-01-01 01:00:03.300,4,ACC
6,1970-01-01 01:00:03.300,1970-01-01 01:00:05.300,4,ACC
7,1970-01-01 01:00:00.000,1970-01-01 01:00:01.300,5,ABS
8,1970-01-01 01:00:00.000,1970-01-01 01:00:01.000,6,ACT
9,1970-01-01 01:00:00.000,1970-01-01 01:00:02.000,7,ACC
10,1970-01-01 01:00:02.000,1970-01-01 01:00:03.300,7,ACC
11,1970-01-01 01:00:03.300,1970-01-01 01:00:05.300,7,ACC
12,1970-01-01 01:00:00.000,1970-01-01 01:00:01.300,8,ABS
13,1970-01-01 01:00:00.000,1970-01-01 01:00:01.000,9,ABU
14,1970-01-01 01:00:00.000,1970-01-01 01:00:01.300,10,ACC
15,1970-01-01 01:00:00.000,1970-01-01 01:00:01.300,11,ABS
16,1970-01-01 01:00:00.000,1970-01-01 …Run Code Online (Sandbox Code Playgroud) 当将 Plotly(在 Python 中)与指示器一起使用时,如果数字相对较大,则数字会四舍五入。如何避免这种情况(或至少控制它)?
fig_ind_abs = go.Figure(go.Indicator(
mode="number+delta",
value=5222,
delta={'position': "top", 'reference': 5218}))
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
语境
我目前正在创建一个数据可视化网络应用程序。我正在使用 Plotly 创建时间序列。我对传说有疑问。
我希望图例保留在底部,因为数据的标签很长,因此会干扰数据的整体尺寸。我选择的方向是水平的。
但当我添加更多数据时,图例会向上移动而不是保持在固定位置,以便可以向下添加新数据。相反,随着新数据添加到图表中,整个图例都会上升。
我的代码如下:
plotly_fig = px.line(data_frame=dataframe_cols1,x=dataframe_cols1.index,y=Columns_select1,
width=780, height=730) # Get data from the dataframe with selected columns, choose the x axis as the index of the dataframe, y axis is the data that will be multiselected
# Legend settings
plotly_fig.update_layout(showlegend=True)
plotly_fig.update_layout(legend=dict(
orientation = "h",
yanchor="bottom",
y=-.50,
xanchor="right",
x=1
))
Run Code Online (Sandbox Code Playgroud)
问题
添加新数据时如何防止图例向上移动?换句话说,如何将图例固定在其位置以防止其与图表“混合”?
import pandas as pd
from pandas import Timestamp
import plotly.express as px
df = pd.DataFrame({'continent': {127: 'South America',
128: 'South America',
129: 'South America',
130: 'South America',
131: 'South America'},
'date': {127: Timestamp('2021-03-01 00:00:00'),
128: Timestamp('2021-03-26 00:00:00'),
129: Timestamp('2021-04-20 00:00:00'),
130: Timestamp('2021-05-15 00:00:00'),
131: Timestamp('2021-06-09 00:00:00')},
'total_cases': {127: 20465329.0,
128: 23470911.0,
129: 26544779.0,
130: 29891133.0,
131: 30534015.0}})
fig = px.bar(df, x='continent', y='total_cases', animation_frame=df.date.astype(str),
# hover_data={'animation_frame':False,
# 'continent':False,
# }
)
fig.update_traces(hovertemplate='Date:%{animation_frame}<br>Total Cases:%{y}')
Run Code Online (Sandbox Code Playgroud)
运行上述代码会输出带有动画滑块的条形图。仅当您不移动滑块时,对悬停标签所做的更改才可见。一旦你这样做并且框架发生变化,默认的plotly.express悬停标签就会重新出现(我认为是因为跟踪更新了)。有什么解决办法吗?
编辑:添加 GIF 来显示问题
我想将我的 gif 传递给加载器组件,而不是使用默认的数字。有人知道该怎么做吗?
这是我的代码:
dcc.Loading(
id="loading-1",
type="default",
children=html.Div(id="loading-output-1"),
)
Run Code Online (Sandbox Code Playgroud)
我正在尝试完成这样的事情:
dcc.Loading(
id="loading-1",
type="assets/dashboard_loader.gif",
children=html.Div(id="loading-output-1"),
)
Run Code Online (Sandbox Code Playgroud)
有人可以指导我吗?
如何删除播放和停止按钮并只保留滑块?
import plotly.express as px
import pandas as pd
df = pd.DataFrame(dict(x=[0, 1, 0, 1],
y=[0, 1, 1, 0],
z=[0, 0, 1, 1]))
px.line(df, "x", "y", animation_frame="z")
Run Code Online (Sandbox Code Playgroud)
pythonplotly小提琴图显示负尾,但没有低于0的值。实际y轴在0到23之间(24小时间隔)。但小提琴图尾部超过 23 且小于 0(第 0 和第 23 边距级别添加到图表中)。
代码:
fig = go.Figure()
fig.add_trace(go.Violin(x=df['Region'][ df['alarm_severity'] == 'CRITICAL' ],
y=df['OccurredTime'][ df['alarm_severity'] == 'CRITICAL' ],
legendgroup='CRITICAL', scalegroup='CRITICAL', name='CRITICAL',
line_color='blue')
)
fig.add_trace(go.Violin(x=df['Region'][ df['alarm_severity'] == 'MAJOR' ],
y=df['OccurredTime'][ df['alarm_severity'] == 'MAJOR' ],
legendgroup='MAJOR', scalegroup='MAJOR', name='MAJOR',
line_color='red')
)
fig.add_trace(go.Violin(x=df['Region'][ df['alarm_severity'] == 'WARNING' ],
y=df['OccurredTime'][ df['alarm_severity'] == 'WARNING' ],
legendgroup='WARNING', scalegroup='WARNING', name='WARNING',
line_color='green')
)
fig.add_trace(go.Violin(x=df['Region'][ df['alarm_severity'] == 'MINOR' ],
y=df['OccurredTime'][ df['alarm_severity'] == 'MINOR' ],
legendgroup='MINOR', scalegroup='MINOR', name='MINOR',
line_color='orange')
)
fig.update_traces(box_visible=True, meanline_visible=True )
fig.update_layout(violinmode='group',width=1000,
height=600)
fig.show()
Run Code Online (Sandbox Code Playgroud) 拥有数据 df,执行以下操作:
fig=px.line(df, x='date', y='px', color='description')
Run Code Online (Sandbox Code Playgroud)
下图的渲染效果如所附图像。这是预期的行为吗?如何使点仅按时间顺序连接?
我正在尝试使用plotly 绘制三个不同的时间序列数据帧(每个数据帧大约有60000 条记录),同时使用不同的背景颜色突出显示周末(和工作时间)。
有没有一种方法可以在不循环遍历整个数据集的情况下完成此解决方案中提到的操作。虽然此方法可能有效,但在大型数据集上性能可能较差
plotly-python ×10
python ×10
plotly ×9
plotly-dash ×2
animation ×1
boxplot ×1
dashboard ×1
flask ×1
pie-chart ×1
time-series ×1
violin-plot ×1