Net Profit Comparison: Easily Understand with Python Visualizations
Hi! In this post, we'll be using the Compare net profit on sales Data to Python visualizationA company's revenue and net income are important indicators of its business performance, and comparing the two at a glance can give you a better understanding of the company's revenue structure.
We'll use two of Python's most popular visualization tools, the Matplotliband Plotlyto graph sales and net profit data. To help beginners follow along, we'll use the Code examples and detailed commentaryfor those looking to get started with data visualization.
What does net profit comparison mean?
Revenueearned by selling a product or service is the Total revenueand say, Net Profitis the final Net Profitin the following example. When comparing revenue and net income together, the ProfitabilityFor example, if sales are increasing but net income is flat, you can evaluate the Increased costscould be a sign that your profit margin has been lowered.
Conversely, if you have a large net profit as a percentage of sales Efficient managementside-by-side, you can see the financial health of the company as a function of the Intuitiveto help you understand. Now let's visualize the two metrics with some real-world example data.
Visualize revenue and net profit with Matplotlib

First, create a Matplotlib library to visualize revenue and net profit data as shown above. Matplotlib is one of the most popular Python Data visualization librarywhich makes it easy to plot different kinds of graphs. I've included the code below with explanations for each step, so you can follow along.
import matplotlib.pyplot as plt
import numpy as np
Set up # data (in thousands of dollars)
companies = ['Nvidia', 'Apple', 'Meta', 'Alphabet', 'Broadcom', 'Microsoft', 'Tesla', 'Amazon']
revenue_per_employee = [3600, 2400, 2200, 1900, 1400, 1100, 777, 410]
profit_per_employee = [2000, 572, 842, 546, 159, 387, 57, 38]
Create and set up the # graph
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 8), sharey=True)
fig.suptitle('Tech Companies: Revenue and Net Income Per Employee (2024)', fontsize=24, fontweight='bold', y=0.95)
# First graph: Revenue per employee
bars1 = ax1.barh(companies, revenue_per_employee, color='green', alpha=0.7)
ax1.set_title('Revenue Per Employee ($K)', fontsize=18, fontweight='bold')
ax1.set_xlabel('Revenue ($K)')
ax1.set_xlim(0, 4000) # Set the x-axis range
ax1.grid(axis='x', linestyle='--', alpha=0.7)
ax1.invert_yaxis() # Reverse list order (higher values up)
# Second graph: Net profit per employee
bars2 = ax2.barh(companies, profit_per_employee, color='lightgreen', alpha=0.7)
ax2.set_title('Net Income Per Employee ($K)', fontsize=18, fontweight='bold')
ax2.set_xlabel('Net Income ($K)')
ax2.set_xlim(0, 4000) # Set the x-axis range
ax2.grid(axis='x', linestyle='--', alpha=0.7)
Show values at the end of the # bars
for ax, bars in zip([ax1, ax2], [bars1, bars2]):
for bar in bars:
width = bar.get_width()
ax.text(width + 50, bar.get_y() + bar.get_height()/2, f'{int(width)}',
va='center', fontsize=12)
# Add grid lines to each bar graph
ax1.set_xticks([0, 1000, 2000, 3000])
ax2.set_xticks([0, 1000, 2000, 3000])
Remove the # box (remove the frame)
ax1.spines['top'].set_visible(False)
ax1.spines['right'].set_visible(False)
ax1.spines['left'].set_visible(False)
ax2.spines['top'].set_visible(False)
ax2.spines['right'].set_visible(False)
ax2.spines['left'].set_visible(False)
# Remove tick lines while keeping y-axis tick labels
ax1.tick_params(axis='y', which='both', length=0)
ax2.tick_params(axis='y', which='both', length=0)
Add a description to the bottom of the #
fig.text(0.5, 0.05, 'Values shown in thousands of dollars ($K) per employee',
ha='center', fontsize=12, style='italic')
fig.text(0.5, 0.03, 'Data for 2024 fiscal year',
ha='center', fontsize=12, style='italic')
Adjust the # layout
plt.tight_layout()
plt.subplots_adjust(top=0.88, bottom=0.1)
Display the # graph
plt.show()Code commentary:
import matplotlib.pyplot as plt: Add the pyplot module of the Matplotlib library for data visualization to theplt.import numpy as np: Install the NumPy library for numerical operations on thenp.companies = ['Nvidia', 'Apple', ...]: The Names of tech companiesas a list.revenue_per_employee = [3600, 2400, ...]: For each company Revenue per employeein thousands of dollars.profit_per_employee = [2000, 572, ...]: For each company Net profit per employeein thousands of dollars.fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 8), sharey=True): 1 row 2 column structure Subplotsfor the image. Set its dimensions to 14 inches wide by 8 inches tall,sharey=Trueso that the two graphs share the y-axis.fig.suptitle(...): the entire graph's Top Titlefor the text. The font size is 24, boldface.bars1 = ax1.barh(companies, revenue_per_employee, color='green', alpha=0.7): In the first subplot, add a company-specific Revenue per employee Data in green Horizontal bar graphsin the center. Set the transparency to 0.7.ax1.set_title(...),ax1.set_xlabel(...): the first graph's Titleand X-axis labelsin the configuration file.ax1.set_xlim(0, 4000): on the x-axis Visible rangefrom 0 to 4000.ax1.grid(axis='x', linestyle='--', alpha=0.7): along the X-axis Dotted gridand set the transparency to 0.7.ax1.invert_yaxis(): Y-axis order to Reverseso that companies with higher data values are at the top.bars2 = ax2.barh(...): In the second subplot, add a company-specific Net profit per employee Data in light green Horizontal bar graphsin the center.for ax, bars in zip([ax1, ax2], [bars1, bars2]): ...: At the end of each bar in both graphs Numerical valuesin a loop that displaysbar.get_width()to get the length of the bar, and displays the value as an integer in its place.ax1.set_xticks([0, 1000, 2000, 3000]): on the x-axis Scalein units of 1000.ax1.spines['top'].set_visible(False)at the top of the graph Remove the spineon the left. Similarly, remove the right and left border lines so that only the X-axis lines remain.ax1.tick_params(axis='y', which='both', length=0): Y-axis Gridlinesbut keep the label.fig.text(...): At the bottom of the graph Additional explanationin italics.plt.tight_layout()between graph elements Optimize spacingin the file.plt.subplots_adjust(top=0.88, bottom=0.1): graph's Top and bottom marginsto fine-tune theplt.show(): Save the completed graph as a Display on screenin the file.
Interactive visualizations with Plotly

This time, the PlotlyLet's visualize the same data using Plotly, which uses the interactive A Python library that makes graphing easy. Where Matplotlib plots static image graphs, Plotly plots graphs with the mouse using the Verify valuesor Zoom in on the graph areato create interactive graphs.
import plotly.graph_objects as go
from plotly.subplots import make_subplots
Set up the data for # (in thousands of dollars)
companies = ['Nvidia', 'Apple', 'Meta', 'Alphabet', 'Broadcom', 'Microsoft', 'Tesla', 'Amazon']
revenue_per_employee = [3600, 2400, 2200, 1900, 1400, 1100, 777, 410]
profit_per_employee = [2000, 572, 842, 546, 159, 387, 57, 38]
Create the # subplots
fig = make_subplots(
rows=1, cols=2,
subplot_titles=('Revenue Per Employee ($K)', 'Net Income Per Employee ($K)'),
shared_yaxes=True,
horizontal_spacing=0.05
)
# First graph: Revenue per employee
fig.add_trace(
go.Bar(
y=companies,
x=revenue_per_employee,
orientation='h',
text=revenue_per_employee,
textposition='outside',
marker=dict(color='green', opacity=0.7),
hovertemplate='<b>%{y}</b><br>Revenue: $%{x}K per employee<extra></extra>'
),
row=1, col=1
)
# Second graph: Net profit per employee
fig.add_trace(
go.Bar(
y=companies,
x=profit_per_employee,
orientation='h',
text=profit_per_employee,
textposition='outside',
marker=dict(color='lightgreen', opacity=0.7),
hovertemplate='<b>%{y}</b><br>Net Income: $%{x}K per employee<extra></extra>'
),
row=1, col=2
)
# full layout settings
fig.update_layout(
title=dict(
text='Tech Companies: Revenue and Net Income Per Employee (2024)',
font=dict(size=24, family='Arial', color='black'),
x=0.5
),
height=600,
width=1000,
showlegend=False,
annotations=[
dict(
text="Values shown in thousands of dollars ($K) per employee<br>Data for 2024 fiscal year",
showarrow=False,
xref="paper",
yref="paper",
x=0.5,
y=-0.15,
font=dict(size=12, style='italic')
)
]
)
Set the # X-axis
fig.update_xaxes(
range=[0, 4000],
gridcolor='lightgray',
gridwidth=1,
griddash='dash',
showline=True,
linecolor='black',
row=1, col=1
)
fig.update_xaxes(
range=[0, 4000],
gridcolor='lightgray',
gridwidth=1,
griddash='dash',
showline=True,
linecolor='black',
row=1, col=2
)
Setting the # Y-axis (removing the frame)
fig.update_yaxes(
showline=False,
showgrid=False,
zeroline=False,
autorange='reversed' # Reverse order so that higher values are on top
)
Display the # graph
fig.show()Code commentary:
import plotly.graph_objects as gofor interactive visualization Plotly Library's graph_objects module togo.from plotly.subplots import make_subplots: In Plotly, the Multiple subplotsfunction for creating thecompanies = ['Nvidia', 'Apple', ...]: The Names of tech companiesas a list.revenue_per_employee = [3600, 2400, ...]: For each company Revenue per employeein thousands of dollars.profit_per_employee = [2000, 572, ...]: For each company Net profit per employeein thousands of dollars.fig = make_subplots(...): 1 row 2 column structure Subplotsfor the new project.subplot_titlesto set the title of each graph,shared_yaxes=Trueto share the y-axis.fig.add_trace(go.Bar(...), row=1, col=1): In the first subplot Horizontal bar graphsto the end of the file.orientation='h'to specify the horizontal orientation,textandtextpositionto display the value outside the bar.marker=dict(color='green', opacity=0.7): bar chart's Colorand Transparencyin the configuration file.hovertemplate='<b>%{y}</b><br>Revenue: $%{x}K per employee<extra></extra>': The About Hoverin the format.fig.add_trace(..., row=1, col=2): Add a second subplot with Net profit datain the same way.fig.update_layout(...): graph's Overall layoutfor the page. Specify the title, size, whether to show a legend, and more.annotations=[dict(...)]: At the bottom of the graph Additional explanationto the end of the file.xref="paper"andyref="paper"to specify the location relative to the entire graph area.fig.update_xaxes(...): on the x-axis Scope, Gridline Styles, Line color and more.griddash='dash'to implement a dotted grid.fig.update_yaxes(showline=False, ...): Y-axis Remove a borderlineand hides the grid and zero lines.autorange='reversed'to sort in reverse order so that companies with higher data values are at the top.fig.show(): the completed Interactive graphsin the center. This graph supports all of Plotly's interactive features, including mouse hover functionality, zooming, and saving images.
Bottom line: The importance of data visualization
Analyze important business metrics like revenue and net profit with Visualizationcan be much easier to understand than just looking at a table of numbers. As we saw above, Python's Matplotlib and Plotly allow beginners to plot beautiful graphs with relatively simple code.
Matplotlib uses the Static imageswhich is great for reports and documents, and Plotly uses the Interactive chartsfor real-time analytics on the web. Both have their pros and cons, so use them to your advantage 🙂 Data visualization is a powerful tool for communicating large amounts of information and gaining insights.
In the future, as you apply it to different data, you may want to consider drawing more complex graphs or using other libraries (e.g., Seaborn, ggplot and more). Continuous practice and learningIt will further develop your eye for understanding this data!
Glossary
- Revenue: A business sells a product or service and earns Total earnings. For example, if you sold 1 million won worth of goods, your revenue is 1 million won.
- Net Profit: subtract all expenses from revenue Profit at the end of the day. Net profit is revenue minus all expenses, including costs, operating expenses, and taxes.
- Visualize your data: Data is presented in a Representation as a chart or graphto visualize. Visualization makes it easy to understand and gain insights from complex data.
- Matplotlib: Python uses the The leading data visualization library. It can draw a variety of charts, including line graphs, bar graphs, and more, and is highly tunable and customizable.
- Plotly: Interactive data visualization librarywhich makes it easy to create web-based interactive charts. Provide interactivity, such as zooming in/out or displaying information on mouseover, to dynamically explore the results of your data analysis.





