# 10 different data charts using Python
pip install matplotlib seaborn
# 1. Line Chart:
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [10, 12, 5, 8, 3]
plt.plot(x, y)
plt.title('Line Chart')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.show()
#clcoding.com
# 2. Bar Chart:
import matplotlib.pyplot as plt
categories = ['A', 'B', 'C', 'D']
values = [25, 40, 30, 20]
plt.bar(categories, values)
plt.title('Bar Chart')
plt.xlabel('Categories')
plt.ylabel('Values')
plt.show()
#clcoding.com
# 3. Pie Chart:
import matplotlib.pyplot as plt
labels = ['Category A', 'Category B', 'Category C']
sizes = [30, 45, 25]
plt.pie(sizes, labels=labels, autopct='%1.1f%%')
plt.title('Pie Chart')
plt.show()
#clcoding.com
# 4. Histogram:
import matplotlib.pyplot as plt
import numpy as np
data = np.random.randn(1000)
plt.hist(data, bins=30, edgecolor='black')
plt.title('Histogram')
plt.xlabel('Values')
plt.ylabel('Frequency')
plt.show()
#clcoding.com
# 5. Scatter Plot:
import matplotlib.pyplot as plt
import numpy as np
x = np.random.rand(50)
y = 2 * x + 1 + 0.1 * np.random.randn(50)
plt.scatter(x, y)
plt.title('Scatter Plot')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.show()
#clcoding.com
# 6. Box Plot:
import seaborn as sns
import numpy as np
data = [np.random.normal(0, std, 100) for std in range(1, 4)]
sns.boxplot(data=data)
plt.title('Box Plot')
plt.xlabel('Category')
plt.ylabel('Values')
plt.show()
#clcoding.com
# 7. Violin Plot:
import seaborn as sns
import numpy as np
data = [np.random.normal(0, std, 100) for std in range(1, 4)]
sns.violinplot(data=data)
plt.title('Violin Plot')
plt.xlabel('Category')
plt.ylabel('Values')
plt.show()
#clcoding.com
# 8. Heatmap:
import seaborn as sns
import numpy as np
data = np.random.rand(10, 10)
sns.heatmap(data, annot=True)
plt.title('Heatmap')
plt.show()
#clcoding.com
# 9. Area Chart:
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y1 = [10, 15, 25, 30, 35]
y2 = [5, 10, 20, 25, 30]
plt.fill_between(x, y1, y2, color='skyblue', alpha=0.4)
plt.title('Area Chart')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.show()
#clcoding.com
# 10. Radar Chart:
import matplotlib.pyplot as plt
import numpy as np
labels = np.array([' A', ' B', ' C', ' D', ' E'])
data = np.array([4, 5, 3, 4, 2])
angles = np.linspace(0, 2 * np.pi, len(labels), endpoint=False)
data = np.concatenate((data, [data[0]]))
angles = np.concatenate((angles, [angles[0]]))
plt.polar(angles, data, marker='o')
plt.fill(angles, data, alpha=0.25)
plt.title('Radar Chart')
plt.show()
#clcoding.com
0 Comments:
Post a Comment