Description:
A Python program that displays a bar chart of sales data and overlays a semi-transparent company logo as a watermark using matplotlib
.
• 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:
Trainings :
Data Science Training in Indore | Data Analytics Training in Indore | Python Training in Indore | Blockchain Training in Indore | React JS Training in Indore | Web Development Training in Indore | Full Stack Development Training in Indore |Free Courses and Resource :
Verbal Aptitude | Matplotlib Tutorials | Examples | Interview Questions | Pandas Tutorials | Projects | Interview Questions | OpenCV Tutorials | Projects | Interview Questions | ExpressJS Tutorials | Projects | Interview Questions | Dart | Python Data Structures and Algorithms | Rust Tutorials | Projects | Interview Questions | Aptitude Tests | HackerRank Python | Django | MongoDB Tutorials | Examples | Interview Questions | NumPy Practice Questions | Python Tutorials by CodersDaily | Golang Tutorials | Projects | Interview Questions | React.js Tutorials | Verbal Ability Tutorial | MS Sql Server Tutorials | Examples | Interview Questions | Power BI Tutorials | Projects | Interview Questions | Example Dashboards | Numpy Tutorials | Projects | Interview Questions | Django REST Framework Tutorial | HackerRank C++ Solutions | Tensor Flow | Pandas Practice Questions | Python Practice Questions | C++ Tutorials | Quantitative Ability Tutorial | Javascript | Node.js Tutorials | HackerRank SQL Solutions | HackerRank DSA Solutions | Verbal Aptitude 2 | HackerRank Java Solutions | HTML Tutorial | TCS NQT Mock Test Series | Reasoning Ability Tutorial | CodeChef Python Solutions | HackerRank C Program Solutions | Leetcode Python Solutions | SQL Practice Question | Matplotlib Practice Questions |Interview Questions :
Pandas Tutorials | Projects | Interview Questions | ExpressJS Tutorials | Projects | Interview Questions | Django | Python Tutorials by CodersDaily | Golang Tutorials | Projects | Interview Questions | Numpy Tutorials | Projects | Interview Questions | Django REST Framework Tutorial |Top Colleges in India :
Indian Institute of Technology Bombay | Jaypee University of Engineering and Technology - Guna |