python坐标轴固定
时间: 2024-01-06 12:26:01 浏览: 248
以下是两种固定坐标轴的方法:
1. 隐藏上轴脊和右轴脊,移动左轴脊和下轴脊的位置:
```python
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpathes
xy = np.array([0.5,0.5])
polygon = mpathes.RegularPolygon(xy, 5, 0.2,color='y')
ax = plt.axes((0.3, 0.3, 0.5, 0.5))
ax.add_patch(polygon)
# 隐藏上轴脊和右轴脊
ax.spines['top'].set_color('none')
ax.spines['right'].set_color('none')
# 移动左轴脊和下轴脊的位置
ax.spines['left'].set_position(('data', 0.5))
ax.spines['bottom'].set_position(('data', 0.5))
plt.title("2020080603052")
plt.show()
```
2. 依次隐藏上轴脊、左轴脊和右轴脊:
```python
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpathes
xy = np.array([0.5,0.5])
polygon = mpathes.RegularPolygon(xy, 5, 0.2,color='y')
ax = plt.axes((0.3, 0.3, 0.5, 0.5))
ax.add_patch(polygon)
# 依次隐藏上轴脊、左轴脊和右轴脊
ax.spines['top'].set_color('none')
ax.spines['left'].set_color('none')
ax.spines['right'].set_color('none')
plt.title("2020080603052")
plt.show()
```
阅读全文