Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 绘图仪扇形图-分段文字颜色和小数点_Python_Plotly_Plotly Dash - Fatal编程技术网

Python 绘图仪扇形图-分段文字颜色和小数点

Python 绘图仪扇形图-分段文字颜色和小数点,python,plotly,plotly-dash,Python,Plotly,Plotly Dash,我创建了一个饼图(代码如下)。即使我在布局中将字体设置为白色,每个饼图段顶部%值的字体颜色也会不同(黑色或白色)。我希望它是所有饼图段上的白色文本 此外,%值的小数位数在饼图段中有所不同,从一个小数点到三个小数点。我想把它设为小数点后一位。有什么建议吗 我无法共享饼图的图像,因为它有一些敏感数据 fig = dcc.Graph( id='graph', figure={ 'data': [{

我创建了一个饼图(代码如下)。即使我在布局中将字体设置为白色,每个饼图段顶部%值的字体颜色也会不同(黑色或白色)。我希望它是所有饼图段上的白色文本

此外,%值的小数位数在饼图段中有所不同,从一个小数点到三个小数点。我想把它设为小数点后一位。有什么建议吗

我无法共享饼图的图像,因为它有一些敏感数据

fig =  dcc.Graph(
            id='graph',
            figure={
                'data': [{
                        'values': df['count'],
                        'labels': df['labels'],
                        'type': 'pie'
                        }],
                'layout': {
                    'margin': {'l': 30,'r': 0,'b': 30,'t': 30,},
                     "plot_bgcolor": "#111111",
                    "paper_bgcolor": "#111111",
                    "font": {"color": 'white'},
                    'legend': {'x': 0, 'y': 1},
                }
            }
        )

对于可以设置的段内的文本颜色:

代码:fig.update_跟踪(insidetextfont=dict(…),selector=dict(type='pie')) 类型:包含下列一个或多个键的dict。 设置位于扇区内的
textinfo
使用的字体

对于可以设置的百分比精度

代码:fig.update_跟踪(texttemplate=,selector=dict(type='pie')) 类型:字符串或字符串数组 默认值:“

用于呈现点上显示的信息文本的模板字符串。请注意,这将覆盖
textinfo
。使用%{variable}插入变量,例如“y:%%{y}”。数字的格式使用d3格式的语法%{variable:d3 format},例如“Price:%%{y:$.2f}”。有关格式化语法的详细信息。使用d3时间格式的语法%{variable | d3 time format}对日期进行格式化,例如“Day:%%{2019-01-01 |%A}”。有关日期格式语法的详细信息。可以为每个点指定的每个属性(即
arrayOk:True
)都可用。变量
标签
颜色
百分比
文本

基于您的代码的示例:

fig = {
    "data": [
        {
            "values": df["count"],
            "labels": df["labels"],
            "type": "pie",
            "insidetextfont": {"color": "white"},
            "texttemplate": "%{percent:.2%f}",
        }
    ],
    "layout": {
        "margin": {
            "l": 30,
            "r": 0,
            "b": 30,
            "t": 30,
        },
        "plot_bgcolor": "#111111",
        "paper_bgcolor": "#111111",
        "font": {"color": "white"},
        "legend": {"x": 0, "y": 1},
    },
}

对于可以设置的段内的文本颜色:

代码:fig.update_跟踪(insidetextfont=dict(…),selector=dict(type='pie')) 类型:包含下列一个或多个键的dict。 设置位于扇区内的
textinfo
使用的字体

对于可以设置的百分比精度

代码:fig.update_跟踪(texttemplate=,selector=dict(type='pie')) 类型:字符串或字符串数组 默认值:“

用于呈现点上显示的信息文本的模板字符串。请注意,这将覆盖
textinfo
。使用%{variable}插入变量,例如“y:%%{y}”。数字的格式使用d3格式的语法%{variable:d3 format},例如“Price:%%{y:$.2f}”。有关格式化语法的详细信息。使用d3时间格式的语法%{variable | d3 time format}对日期进行格式化,例如“Day:%%{2019-01-01 |%A}”。有关日期格式语法的详细信息。可以为每个点指定的每个属性(即
arrayOk:True
)都可用。变量
标签
颜色
百分比
文本

基于您的代码的示例:

fig = {
    "data": [
        {
            "values": df["count"],
            "labels": df["labels"],
            "type": "pie",
            "insidetextfont": {"color": "white"},
            "texttemplate": "%{percent:.2%f}",
        }
    ],
    "layout": {
        "margin": {
            "l": 30,
            "r": 0,
            "b": 30,
            "t": 30,
        },
        "plot_bgcolor": "#111111",
        "paper_bgcolor": "#111111",
        "font": {"color": "white"},
        "legend": {"x": 0, "y": 1},
    },
}

谢谢你的作品great谢谢你的作品很棒