Loading...
Loading...
Compare original and translation side by side
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
plt.show()import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3, 4])
ax.set_ylabel('some numbers')
plt.show()import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
plt.show()import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3, 4])
ax.set_ylabel('some numbers')
plt.show()import matplotlib.pyplot as plt
import numpy as npimport matplotlib.pyplot as plt
import numpy as npundefinedundefinedundefinedundefinedundefinedundefinedax.plot(x, y, linewidth=2, linestyle='--', marker='o', color='blue')ax.scatter(x, y, s=sizes, c=colors, alpha=0.6, cmap='viridis')ax.bar(categories, values, color='steelblue', edgecolor='black')ax.plot(x, y, linewidth=2, linestyle='--', marker='o', color='blue')ax.scatter(x, y, s=sizes, c=colors, alpha=0.6, cmap='viridis')ax.bar(categories, values, color='steelblue', edgecolor='black')
**Histograms** - Distributions
```python
ax.hist(data, bins=30, edgecolor='black', alpha=0.7)im = ax.imshow(matrix, cmap='coolwarm', aspect='auto')
plt.colorbar(im, ax=ax)contour = ax.contour(X, Y, Z, levels=10)
ax.clabel(contour, inline=True, fontsize=8)ax.boxplot([data1, data2, data3], labels=['A', 'B', 'C'])ax.violinplot([data1, data2, data3], positions=[1, 2, 3])references/plot_types.md
**直方图** - 数据分布展示
```python
ax.hist(data, bins=30, edgecolor='black', alpha=0.7)im = ax.imshow(matrix, cmap='coolwarm', aspect='auto')
plt.colorbar(im, ax=ax)contour = ax.contour(X, Y, Z, levels=10)
ax.clabel(contour, inline=True, fontsize=8)ax.boxplot([data1, data2, data3], labels=['A', 'B', 'C'])ax.violinplot([data1, data2, data3], positions=[1, 2, 3])references/plot_types.md'red''blue''steelblue''#FF5733'(0.1, 0.2, 0.3)cmap='viridis'cmap='plasma'cmap='coolwarm'plt.style.use('seaborn-v0_8-darkgrid') # Apply predefined style'red''blue''steelblue''#FF5733'(0.1, 0.2, 0.3)cmap='viridis'cmap='plasma'cmap='coolwarm'plt.style.use('seaborn-v0_8-darkgrid') # 应用预定义样式
**Customizing with rcParams:**
```python
plt.rcParams['font.size'] = 12
plt.rcParams['axes.labelsize'] = 14
plt.rcParams['axes.titlesize'] = 16
plt.rcParams['xtick.labelsize'] = 10
plt.rcParams['ytick.labelsize'] = 10
plt.rcParams['legend.fontsize'] = 12
plt.rcParams['figure.titlesize'] = 18ax.text(x, y, 'annotation', fontsize=12, ha='center')
ax.annotate('important point', xy=(x, y), xytext=(x+1, y+1),
arrowprops=dict(arrowstyle='->', color='red'))references/styling_guide.md
**使用rcParams自定义:**
```python
plt.rcParams['font.size'] = 12
plt.rcParams['axes.labelsize'] = 14
plt.rcParams['axes.titlesize'] = 16
plt.rcParams['xtick.labelsize'] = 10
plt.rcParams['ytick.labelsize'] = 10
plt.rcParams['legend.fontsize'] = 12
plt.rcParams['figure.titlesize'] = 18ax.text(x, y, 'annotation', fontsize=12, ha='center')
ax.annotate('important point', xy=(x, y), xytext=(x+1, y+1),
arrowprops=dict(arrowstyle='->', color='red'))references/styling_guide.mdundefinedundefined
**Important parameters:**
- `dpi`: Resolution (300 for publications, 150 for web, 72 for screen)
- `bbox_inches='tight'`: Removes excess whitespace
- `facecolor='white'`: Ensures white background (useful for transparent themes)
- `transparent=True`: Transparent background
**重要参数:**
- `dpi`:分辨率(出版物用300dpi,网页用150dpi,屏幕显示用72dpi)
- `bbox_inches='tight'`:移除多余空白
- `facecolor='white'`:确保白色背景(适用于透明主题)
- `transparent=True`:透明背景from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111, projection='3d')from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111, projection='3d')undefinedundefinedfig, ax = plt.subplots(figsize=(10, 6))fig, ax = plt.subplots(figsize=(10, 6))constrained_layout=Truetight_layout()fig, ax = plt.subplots(constrained_layout=True)constrained_layout=Truetight_layout()fig, ax = plt.subplots(constrained_layout=True)rasterized=Truerasterized=Trueundefinedundefined# Plot data
ax.plot(data['x'], data['y'], linewidth=2)
# Customize
ax.set_xlabel('X Axis Label', fontsize=12)
ax.set_ylabel('Y Axis Label', fontsize=12)
ax.set_title(title, fontsize=14, fontweight='bold')
ax.grid(True, alpha=0.3)
return fig, ax# 绘制数据
ax.plot(data['x'], data['y'], linewidth=2)
# 自定义设置
ax.set_xlabel('X Axis Label', fontsize=12)
ax.set_ylabel('Y Axis Label', fontsize=12)
ax.set_title(title, fontsize=14, fontweight='bold')
ax.grid(True, alpha=0.3)
return fig, axundefinedundefinedscripts/scripts/plot_template.pyplot_template.pypython scripts/plot_template.pypython scripts/plot_template.pystyle_configurator.pystyle_configurator.pypython scripts/style_configurator.pypython scripts/style_configurator.pyreferences/plot_types.mdreferences/styling_guide.mdreferences/api_reference.mdreferences/common_issues.mdreferences/plot_types.mdreferences/styling_guide.mdreferences/api_reference.mdreferences/common_issues.md%matplotlib inline%matplotlib widget%matplotlib inline%matplotlib widgetconstrained_layout=Truetight_layout()plt.close(fig)plt.rcParams['font.sans-serif']pixels = dpi * inchesconstrained_layout=Truetight_layout()plt.close(fig)plt.rcParams['font.sans-serif']pixels = dpi * inches