Instagram
youtube
Facebook
Twitter

Add a Company Logo as a Watermark

Description:
A Python program that displays a bar chart of sales data and overlays a semi-transparent company logo as a watermark using matplotlib.

Code Explanation:

• Imports matplotlib.pyplot for plotting and matplotlib.image to load the logo image.
• Defines products and sales lists as sample data for plotting.
• Creates a bar chart using plt.bar() with product names on the X-axis and sales on the Y-axis.
• Loads the company logo from the specified file path using mpimg.imread().
• Uses plt.imshow() to overlay the logo on the chart with extent to control size and position.
• Applies alpha=0.2 to make the logo semi-transparent like a watermark.
• Sets the chart title and axis labels for better understanding.
• Adds grid lines for improved readability of the chart.
• Uses plt.tight_layout() to adjust spacing automatically and plt.show() to display the final plot.

 

Program:

# 39. Add a company logo as a watermark.

import matplotlib.pyplot as plt
import matplotlib.image as mpimg

# Sample sales data
products = ['Laptop', 'Tablet', 'Smartphone', 'Headphones']
sales = [1500, 1500, 1500, 500]

# Create a bar chart
plt.figure(figsize=(8, 6))
plt.bar(products, sales, color='skyblue')

# Load and add the logo as a watermark
logo = mpimg.imread(r"C:\Users\Vijay Pandey\OneDrive\Desktop\matploatlib_questions\bk2mg.jpg")
plt.imshow(logo, extent=[-0.5, 3.5, 200, 1800], aspect='auto', alpha=0.2)

# Add titles and labels
plt.title("Sales by Product with Company Logo")
plt.xlabel("Product")
plt.ylabel("Sales")
plt.grid(True)

# Show the plot
plt.tight_layout()
plt.show()

 

Output: