# contour等高线绘制

```python
import numpy as np
import matplotlib.pyplot as plt


def height(x, y):
    return (1 - x / 2 + x ** 5 + y ** 3) * np.exp(-x ** 2 - y ** 2)


x = np.linspace(-3, 3, 300)
y = np.linspace(-3, 3, 300)
X, Y = np.meshgrid(x, y)
# 为等高线填充颜色 10表示按照高度分成10层
plt.contourf(X, Y, height(X, Y), 10, alpha=0.75, cmap=plt.cm.hot)
C = plt.contour(X, Y, height(X, Y), 10, colors='black')
# 绘制等高线标签
plt.clabel(C, inline=True, fontsize=10)
# 去掉坐标轴刻度
# plt.xticks(())
# plt.yticks(())
plt.show()
# 显示图片
```

![img](/files/-Lpsm_oYvVzpq9k5kuaO)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://im-qianuxn.gitbook.io/pytorch/ji-suan-ji/numpy-pandas-matplotlib/matplotlib/contour.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
