Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to set the font style to Bold in Python Plotly?
Plotly is an open-source Python library for creating interactive charts and visualizations. You can customize font styles, including making text bold, using various methods. In this tutorial, we will show how to set font styles to bold in Python Plotly.
Methods to Make Text Bold in Plotly
There are several ways to make text bold in Plotly ?
Use HTML <b> tags in titles and annotations
Set font_family to bold fonts like "Arial Black"
Use font_weight property for specific elements
Method 1: Using HTML Tags for Bold Titles
The simplest way to make titles bold is using HTML <b> tags ?
import plotly.graph_objects as go
import pandas as pd
# Create sample data
data = {
'categories': ['A', 'B', 'C', 'D', 'E'],
'values': [12, 13, 11, 14, 15]
}
df = pd.DataFrame(data)
# Create bar chart with bold title
fig = go.Figure(go.Bar(
x=df['categories'],
y=df['values']
))
# Set bold title using HTML tags
fig.update_layout(title='<b>Sales Performance by Category</b>')
fig.show()
Method 2: Using Bold Font Family
You can use bold font families for axis labels and other text elements ?
import plotly.graph_objects as go
import pandas as pd
# Create sample data
data = {
'months': ['Jan', 'Feb', 'Mar', 'Apr', 'May'],
'sales': [100, 120, 110, 140, 130]
}
df = pd.DataFrame(data)
# Create line chart
fig = go.Figure(go.Scatter(
x=df['months'],
y=df['sales'],
mode='lines+markers',
name='Sales'
))
# Apply bold formatting to various elements
fig.update_layout(
title='<b>Monthly Sales Trend</b>',
xaxis_title='<b>Months</b>',
yaxis_title='<b>Sales (in thousands)</b>'
)
# Make axis tick labels bold
fig.update_xaxes(tickfont_family="Arial Black")
fig.update_yaxes(tickfont_family="Arial Black")
fig.show()
Method 3: Using Font Dictionary for Complete Control
For more control over font styling, use font dictionaries ?
import plotly.graph_objects as go
# Create sample data
categories = ['Product A', 'Product B', 'Product C', 'Product D']
values = [25, 35, 30, 40]
# Create bar chart
fig = go.Figure(go.Bar(
x=categories,
y=values,
marker_color=['#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4']
))
# Apply comprehensive bold styling
fig.update_layout(
title={
'text': '<b>Product Performance Dashboard</b>',
'font': {'size': 20, 'family': 'Arial Black'}
},
xaxis={
'title': '<b>Products</b>',
'tickfont': {'family': 'Arial Black', 'size': 12}
},
yaxis={
'title': '<b>Performance Score</b>',
'tickfont': {'family': 'Arial Black', 'size': 12}
},
font={'family': 'Arial Black'}
)
fig.show()
Comparison of Bold Text Methods
| Method | Use Case | Syntax |
|---|---|---|
| HTML <b> tags | Titles, annotations | '<b>Text</b>' |
| Bold font family | Axis labels, tick labels | tickfont_family="Arial Black" |
| Font dictionary | Complete control | font={'family': 'Arial Black'} |
Conclusion
Use HTML <b> tags for quick bold titles and labels. For axis styling, use tickfont_family="Arial Black". Font dictionaries provide the most control over bold text formatting in Plotly visualizations.
