Python Visualization
What is Visualization?
Python offers various libraries for data visualization, and two popular ones are Matplotlib and Seaborn.
Matplotlib:
Installing Matplotlib:
pip install matplotlib
Basic Matplotlib Examples:
Line Plot:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y = np.sin(x)
plt.plot(x, y)
plt.title('Sinusoidal Function')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.show()
Scatter Plot:
import matplotlib.pyplot as plt
import numpy as np
x = np.random.rand(50)
y = np.random.rand(50)
plt.scatter(x, y, color='blue', marker='o')
plt.title('Scatter Plot')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.show()
Seaborn:
Installing Seaborn:
pip install seaborn
Basic Seaborn Examples:
Scatter Plot with Seaborn:
import seaborn as sns
import numpy as np
x = np.random.rand(50)
y = np.random.rand(50)
sns.scatterplot(x, y)
plt.title('Scatter Plot with Seaborn')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.show()
Histogram with Seaborn:
import seaborn as sns
import numpy as np
data = np.random.randn(1000) # Generating random data
sns.histplot(data, bins=30, kde=True, color='green')
plt.title('Histogram with Seaborn')
plt.xlabel('Value')
plt.ylabel('Frequency')
plt.show()
These examples cover basic visualization using Matplotlib and Seaborn. You can create various types of plots, customize them, and visualize data in different ways using these libraries. Depending on your specific needs, you might explore other visualization libraries like Plotly or Bokeh as well.