编写程序,自定义坐标轴区间和子图,绘制散点图、柱状图、直方图、折线图、饼图、等值线图、雷达图中的至少三种,要求提交源代码和运行结果截图。
时间: 2023-07-10 20:33:34 浏览: 109
基于jfreechart开发图
好的,我会回答你的问题。但是,我是一个语言模型AI,无法提供源代码和运行结果截图。但我可以为您提供一些思路和建议。
对于编写程序,自定义坐标轴区间和子图,绘制散点图、柱状图、直方图、折线图、饼图、等值线图、雷达图中的至少三种,可以选择使用Python中的Matplotlib库来完成。
下面是每种图表的示例代码和简要说明:
1. 散点图
```python
import matplotlib.pyplot as plt
import numpy as np
x = np.random.rand(50)
y = np.random.rand(50)
colors = np.random.rand(50)
area = np.pi * (15 * np.random.rand(50))**2
fig, ax = plt.subplots()
ax.scatter(x, y, s=area, c=colors, alpha=0.5)
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_title('Scatter Plot')
plt.show()
```
2. 柱状图
```python
import matplotlib.pyplot as plt
import numpy as np
x = np.array(['A', 'B', 'C', 'D', 'E'])
y = np.array([10, 20, 30, 40, 50])
fig, ax = plt.subplots()
ax.bar(x, y)
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_title('Bar Chart')
plt.show()
```
3. 直方图
```python
import matplotlib.pyplot as plt
import numpy as np
x = np.random.normal(size=1000)
fig, ax = plt.subplots()
ax.hist(x, bins=30)
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_title('Histogram')
plt.show()
```
4. 折线图
```python
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y = np.sin(x)
fig, ax = plt.subplots()
ax.plot(x, y)
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_title('Line Chart')
plt.show()
```
5. 饼图
```python
import matplotlib.pyplot as plt
labels = ['A', 'B', 'C', 'D']
sizes = [15, 30, 45, 10]
fig, ax = plt.subplots()
ax.pie(sizes, labels=labels, autopct='%1.1f%%')
ax.set_title('Pie Chart')
plt.show()
```
6. 等值线图
```python
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-3, 3, 100)
y = np.linspace(-3, 3, 100)
X, Y = np.meshgrid(x, y)
Z = np.sin(np.sqrt(X**2 + Y**2))
fig, ax = plt.subplots()
ax.contour(X, Y, Z)
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_title('Contour Plot')
plt.show()
```
7. 雷达图
```python
import matplotlib.pyplot as plt
import numpy as np
labels = ['A', 'B', 'C', 'D', 'E']
data = np.array([10, 20, 30, 40, 50])
angles = np.linspace(0, 2*np.pi, len(labels), endpoint=False)
data = np.concatenate((data, [data[0]]))
angles = np.concatenate((angles, [angles[0]]))
fig, ax = plt.subplots(polar=True)
ax.plot(angles, data, 'o-', linewidth=2)
ax.fill(angles, data, alpha=0.25)
ax.set_thetagrids(angles * 180/np.pi, labels)
ax.set_title('Radar Chart')
plt.show()
```
以上是每种图表的示例代码和简要说明。您可以根据需要进行调整和修改,以满足您的具体需求。
阅读全文