折线图拳交 小说
import matplotlib.pyplot as pltimport seaborn as snsimport numpy as np# 建造立场sns.set(style='whitegrid')# 生成数据x = np.linspace(0, 10, 100)y1 = np.sin(x)y2 = np.cos(x)# 创建图表plt.figure(figsize=(10, 6))plt.plot(x, y1, label='Sine Wave', color='b', linewidth=2)plt.plot(x, y2, label='Cosine Wave', color='r', linestyle='--', linewidth=2)# 添加遮拦plt.fill_between(x, y1, y2, color='gray', alpha=0.1)plt.title('Line Plot', fontsize=15)plt.xlabel('X-axis', fontsize=12)plt.ylabel('Y-axis', fontsize=12)plt.legend()plt.show()图片拳交 小说
2. 散点图import matplotlib.pyplot as pltimport seaborn as snsimport numpy as np# 建造立场sns.set(style='whitegrid')# 生成数据x = np.random.rand(100)y = np.random.rand(100)colors = np.random.rand(100)sizes = 1000 * np.random.rand(100)# 创建图表plt.figure(figsize=(10, 6))plt.scatter(x, y, c=colors, s=sizes, alpha=0.5, cmap='viridis')plt.colorbar()# 添加遮拦plt.title('Scatter Plot', fontsize=15)plt.xlabel('X-axis', fontsize=12)plt.ylabel('Y-axis', fontsize=12)plt.show()
图片
3. 条形图import matplotlib.pyplot as pltimport seaborn as sns# 建造立场sns.set(style='whitegrid')# 生成数据categories = ['A', 'B', 'C', 'D']values1 = [5, 7, 8, 6]values2 = [3, 4, 5, 2]# 创建图表fig, ax = plt.subplots(figsize=(10, 6))bar1 = ax.bar(categories, values1, label='Group 1')bar2 = ax.bar(categories, values2, bottom=values1, label='Group 2')# 添加遮拦ax.set_title('Stacked Bar Chart', fontsize=15)ax.set_xlabel('Categories', fontsize=12)ax.set_ylabel('Values', fontsize=12)ax.legend()# 添加数值标签for rect in bar1 + bar2: height = rect.get_height() ax.annotate(f'{height}', xy=(rect.get_x() + rect.get_width() / 2, height), xytext=(0, 3), textcoords='offset points', ha='center', va='bottom')plt.show()图片
4. 热力求import matplotlib.pyplot as pltimport seaborn as snsimport numpy as np# 生成数据data = np.random.rand(10, 12)# 创建热图plt.figure(figsize=(10, 6))sns.heatmap(data, annot=True, fmt='.2f', cmap='coolwarm')# 添加遮拦plt.title('Heatmap', fontsize=15)plt.show()
图片
5. 箱线图import matplotlib.pyplot as pltimport seaborn as snsimport numpy as np# 建造立场sns.set(style='whitegrid')# 生成数据data = np.random.normal(size=(20, 6)) + np.arange(6) / 2# 创建图表plt.figure(figsize=(10, 6))sns.boxplot(data=data, palette='vlag')# 添加遮拦plt.title('Box Plot', fontsize=15)plt.show()图片
6. 蜘蛛图import numpy as npimport matplotlib.pyplot as pltimport seaborn as sns# 建造立场sns.set(style='whitegrid')# 数据准备labels = np.array(['A', 'B', 'C', 'D', 'E'])stats = [10, 20, 30, 40, 50]stats2 = [30, 10, 20, 30, 40]# 创建蜘蛛图angles = np.linspace(0, 2 * np.pi, len(labels), endpoint=False).tolist()stats = np.concatenate((stats, [stats[0]]))stats2 = np.concatenate((stats2, [stats2[0]]))angles += angles[:1]fig, ax = plt.subplots(figsize=(8, 8), subplot_kw=dict(polar=True))ax.fill(angles, stats, color='blue', alpha=0.25, label='Group 1')ax.plot(angles, stats, color='blue', linewidth=2)ax.fill(angles, stats2, color='red', alpha=0.25, label='Group 2')ax.plot(angles, stats2, color='red', linewidth=2)ax.set_yticklabels([])ax.set_xticks(angles[:-1])ax.set_xticklabels(labels, fontsize=12)ax.grid(True)# 添加标题和图例plt.title('Enhanced Spider Chart', size=20, color='black', y=1.1)plt.legend(loc='upper right', bbox_to_anchor=(0.1, 0.1))plt.show()
图片
7. 双轴图import matplotlib.pyplot as pltimport seaborn as snsimport numpy as np# 建造立场sns.set(style='whitegrid')# 生成数据x = np.linspace(0, 10, 100)y1 = np.sin(x)y2 = np.cos(x)# 创建图表fig, ax1 = plt.subplots(figsize=(10, 6))ax2 = ax1.twinx()ax1.plot(x, y1, 'g-')ax2.plot(x, y2, 'b-')# 添加遮拦ax1.set_xlabel('X-axis')ax1.set_ylabel('Sine', color='g')ax2.set_ylabel('Cosine', color='b')plt.title('Dual Axis Plot')plt.show()图片
8. 面积图import matplotlib.pyplot as pltimport seaborn as snsimport numpy as np# 建造立场sns.set(style='whitegrid')# 生成数据x = np.linspace(0, 10, 100)y1 = np.sin(x)y2 = np.cos(x)# 创建图表plt.figure(figsize=(10, 6))plt.fill_between(x, y1, color='skyblue', alpha=0.4)plt.fill_between(x, y2, color='orange', alpha=0.4)# 添加遮拦plt.title('Area Chart', fontsize=15)plt.xlabel('X-axis', fontsize=12)plt.ylabel('Y-axis', fontsize=12)plt.show()
图片
9. 带状图import matplotlib.pyplot as pltimport seaborn as snsimport numpy as np# 建造立场sns.set(style='whitegrid')# 生成数据x = np.linspace(0, 10, 100)y = np.sin(x)z = np.sin(x) + np.random.normal(0, 0.1, 100)# 创建图表plt.figure(figsize=(10, 6))plt.plot(x, y, label='Sine Wave')plt.fill_between(x, y, z, where=(y >= z), interpolate=True, color='green', alpha=0.3)plt.fill_between(x, y, z, where=(y < z), interpolate=True, color='red', alpha=0.3)# 添加遮拦plt.title('Band Chart', fontsize=15)plt.xlabel('X-axis', fontsize=12)plt.ylabel('Y-axis', fontsize=12)plt.legend()plt.show()图片
10. 等高线图import numpy as npimport matplotlib.pyplot as pltimport seaborn as sns# 建造立场sns.set(style='white')# 数据准备x = np.linspace(-5, 5, 50)y = np.linspace(-5, 5, 50)X, Y = np.meshgrid(x, y)Z = np.sin(np.sqrt(X**2 + Y**2))# 创建等高线图plt.figure(figsize=(10, 6))contour = plt.contourf(X, Y, Z, cmap='coolwarm', levels=20)plt.colorbar(contour)# 添加遮拦plt.title('Contour Plot', fontsize=15)plt.show()
图片
11. 极坐标图import numpy as npimport matplotlib.pyplot as pltimport seaborn as sns# 建造立场sns.set(style='white')# 数据准备theta = np.linspace(0, 2*np.pi, 100)r = np.abs(np.sin(theta) * np.cos(theta))# 创建极坐标图plt.figure(figsize=(8, 8))ax = plt.subplot(111, polar=True)ax.plot(theta, r, color='b', linewidth=2)# 添加遮拦plt.title('Polar Plot', fontsize=15)plt.show()图片
12. 3D曲面图import numpy as npimport matplotlib.pyplot as pltfrom mpl_toolkits.mplot3d import Axes3Dimport seaborn as sns# 建造立场sns.set(style='white')# 数据准备x = np.linspace(-5, 5, 50)y = np.linspace(-5, 5, 50)X, Y = np.meshgrid(x, y)Z = np.sin(np.sqrt(X**2 + Y**2))# 创建3D曲面图fig = plt.figure(figsize=(10, 6))ax = fig.add_subplot(111, projection='3d')surf = ax.plot_surface(X, Y, Z, cmap='viridis')fig.colorbar(surf)# 添加遮拦plt.title('3D Surface Plot', fontsize=15)plt.show()
图片
13. 3D散点图import numpy as npimport matplotlib.pyplot as pltfrom mpl_toolkits.mplot3d import Axes3Dimport seaborn as sns# 建造立场sns.set(style='white')# 数据准备x = np.random.standard_normal(100)y = np.random.standard_normal(100)z = np.random.standard_normal(100)# 创建3D散点图fig = plt.figure(figsize=(10, 6))ax = fig.add_subplot(111, projection='3d')scatter = ax.scatter(x, y, z, c=z, cmap='viridis')# 添加遮拦fig.colorbar(scatter)plt.title('3D Scatter Plot', fontsize=15)plt.show()图片
14. 3D条形图import numpy as npimport matplotlib.pyplot as pltfrom mpl_toolkits.mplot3d import Axes3Dimport seaborn as sns# 建造立场sns.set(style='white')# 数据准备x = np.arange(1, 11)y = np.random.randint(1, 10, 10)z = np.zeros(10)# 创建3D条形图fig = plt.figure(figsize=(10, 6))ax = fig.add_subplot(111, projection='3d')bars = ax.bar3d(x, y, z, 1, 1, y, shade=True)# 添加遮拦plt.title('3D Bar Plot', fontsize=15)plt.show()
图片
15. 直方图import matplotlib.pyplot as pltimport seaborn as snsimport numpy as np# 建造立场sns.set(style='whitegrid')# 生成数据data = np.random.randn(1000)# 创建图表plt.figure(figsize=(10, 6))sns.histplot(data, kde=True, color='purple', bins=30)# 添加遮拦plt.title('Histogram', fontsize=15)plt.xlabel('Value', fontsize=12)plt.ylabel('Frequency', fontsize=12)plt.show()图片
16.小提琴图
import matplotlib.pyplot as pltimport seaborn as snsimport numpy as np# 建造立场sns.set(style='whitegrid')# 生成数据data = np.random.normal(size=(20, 6)) + np.arange(6) / 2# 创建图表plt.figure(figsize=(10, 6))sns.violinplot(data=data, palette='muted')# 添加遮拦plt.title('Violin Plot', fontsize=15)plt.show()
图片
17.成对关联图
r级书屋春色吧import seaborn as snsimport matplotlib.pyplot as plt# 生成数据iris = sns.load_dataset('iris')# 创建图表sns.pairplot(iris, hue='species', palette='muted')plt.suptitle('Pair Plot', y=1.02, fontsize=15)plt.show()图片
18. Facet Grid 图
import seaborn as snsimport matplotlib.pyplot as plt# 生成数据tips = sns.load_dataset('tips')# 创建图表g = sns.FacetGrid(tips, col='time', row='smoker', margin_titles=True)g.map(sns.scatterplot, 'total_bill', 'tip', alpha=.7)g.add_legend()# 添加遮拦plt.suptitle('Facet Grid', y=1.02, fontsize=15)plt.show()
图片
本站仅提供存储办事,整个本色均由用户发布,如发现存害或侵权本色,请点击举报。