抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

一方の笔记本

The only source of knowledge is experience.

记录一下细节方面可能出现的问题。

基础用法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.axisartist.axislines import AxesZero

fig = plt.figure()
ax = fig.add_subplot(axes_class=AxesZero)

ax.set_xlabel('x')
ax.set_ylabel('y')

ax.grid(True, color='#b0b0b0') # default color: #b0b0b0

for direction in ["xzero", "yzero"]:
# adds arrows at the ends of each axis
ax.axis[direction].set_axisline_style("-|>")

# adds X and Y-axis from the origin
ax.axis[direction].set_visible(True)

for direction in ["left", "right", "bottom", "top"]:
# hides borders
ax.axis[direction].set_visible(False)

x = np.linspace(-2 * np.pi, 2 * np.pi, 80)
y = np.sin(x)

ax.plot(x, y, linestyle='--', color='red', marker='*')

ax.set_xticks(np.linspace(-2 * np.pi, 2 * np.pi, 5), ["$-2\pi$", "$-\pi$", "$0$", "$\pi$", "$2\pi$"])

# ax.spines['bottom'].set_position(("data", 0))
# ax.spines['left'].set_position(("data", 0))

plt.show()

评论