Data Science Machine Learning Data Analysis
37.1K subscribers
1.13K photos
27 videos
39 files
1.24K links
This channel is for Programmers, Coders, Software Engineers.

1- Data Science
2- Machine Learning
3- Data Visualization
4- Artificial Intelligence
5- Data Analysis
6- Statistics
7- Deep Learning

Cross promotion and ads: @hussein_sheikho
加入频道
Topic: Python Matplotlib – From Easy to Top: Part 1 of 6: Introduction and Basic Plotting

---

### 1. What is Matplotlib?

Matplotlib is the most widely used Python library for data visualization.

• It provides an object-oriented API for embedding plots into applications and supports a wide variety of graphs: line charts, bar charts, scatter plots, histograms, etc.

---

### 2. Installing and Importing Matplotlib

Install Matplotlib if you haven't:

pip install matplotlib


Import the main module and pyplot interface:

import matplotlib.pyplot as plt
import numpy as np


---

### 3. Plotting a Basic Line Chart

x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]

plt.plot(x, y)
plt.title("Simple Line Plot")
plt.xlabel("X Axis")
plt.ylabel("Y Axis")
plt.grid(True)
plt.show()


---

### 4. Customizing Line Style, Color, and Markers

plt.plot(x, y, color='green', linestyle='--', marker='o', label='Data')
plt.title("Styled Line Plot")
plt.xlabel("X Axis")
plt.ylabel("Y Axis")
plt.legend()
plt.show()


---

### 5. Adding Multiple Lines to a Plot

x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)

plt.plot(x, y1, label="sin(x)", color='blue')
plt.plot(x, y2, label="cos(x)", color='red')
plt.title("Multiple Line Plot")
plt.xlabel("X Axis")
plt.ylabel("Y Axis")
plt.legend()
plt.grid(True)
plt.show()


---

### 6. Scatter Plot

Used to show relationships between two variables.

x = np.random.rand(100)
y = np.random.rand(100)

plt.scatter(x, y, color='purple', alpha=0.6)
plt.title("Scatter Plot")
plt.xlabel("X Axis")
plt.ylabel("Y Axis")
plt.show()


---

### 7. Bar Chart

categories = ['A', 'B', 'C', 'D']
values = [4, 7, 2, 5]

plt.bar(categories, values, color='skyblue')
plt.title("Bar Chart Example")
plt.xlabel("Category")
plt.ylabel("Value")
plt.show()


---

### 8. Histogram

data = np.random.randn(1000)

plt.hist(data, bins=30, color='orange', edgecolor='black')
plt.title("Histogram")
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.show()


---

### 9. Saving the Plot to a File

plt.plot([1, 2, 3], [4, 5, 6])
plt.savefig("plot.png")


---

### 10. Summary

matplotlib.pyplot is the key module for creating all kinds of plots.
• You can customize styles, add labels, titles, and legends.
• Understanding basic plots is the foundation for creating advanced visualizations.

---

Exercise

• Plot y = x^2 and y = x^3 on the same figure.
• Create a scatter plot of 100 random points.
• Create and save a histogram from a normal distribution sample of 500 points.

---

#Python #Matplotlib #DataVisualization #Plots #Charts

https://yangx.top/DataScienceM
3
🔥 Trending Repository: WrenAI

📝 Description: ⚡️ GenBI (Generative BI) queries any database in natural language, generates accurate SQL (Text-to-SQL), charts (Text-to-Chart), and AI-powered insights in seconds.

🔗 Repository URL: https://github.com/Canner/WrenAI

🌐 Website: https://getwren.ai/oss

📖 Readme: https://github.com/Canner/WrenAI#readme

📊 Statistics:
🌟 Stars: 10.1K stars
👀 Watchers: 70
🍴 Forks: 1K forks

💻 Programming Languages: TypeScript - Python - Go - JavaScript - Less - Dockerfile

🏷️ Related Topics:
#agent #bigquery #charts #sql #postgresql #bedrock #business_intelligence #openai #spreadsheets #vertex #genbi #text_to_sql #rag #text2sql #duckdb #llm #anthropic #sqlai #text_to_chart


==================================
🧠 By: https://yangx.top/DataScienceM