'Plotly: How to use a built-in colorscale in a pie chart?

I am just trying to learn python. Can someone help to understand how to add px.colors.qualitative.Pastel2 into the below code.

import dash
import dash_core_components as dcc
import dash_html_components as html
import pyodbc
import plotly.offline as pyo
import plotly.graph_objs as go
import pandas as pd
import plotly.express as px

connection = pyodbc.connect('Driver={SQL Server};'
                          'Server=sqlserver;'
                          'Database=mydatabase;'
                          'UID =sa;'
                          'PWD = sa123;')

app = dash.Dash()
sql_data=pd.read_sql_query("select columna, columnb from table", connection)
piechart = go.Pie(labels=sql_data['columna'], values=sql_data['columnb'])

app.layout = html.Div(children=[    
            dcc.Graph(id='example',
            figure={'data': [piechart],
                'layout': {'title': 'PieChart Sample'}
                })
 ])

Thanks



Solution 1:[1]

Use something like color_discrete_sequence=px.colors.qualitative.G10 when creating your figure. You can also update the layout's colorway attribute. You can find more info, as well as a visualization of the included color scales, here: https://plotly.com/python/discrete-color/. Cheers!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Managarm