各年作品出版数量折线图 各价位作品数量直方图 各出版社出版作品数量条形图&评分折线图 作者作品评分条形图 作品评分树状图代码
时间: 2023-11-16 22:08:00 浏览: 21
折线图示例代码:
```python
import matplotlib.pyplot as plt
# 准备数据
years = [2015, 2016, 2017, 2018, 2019, 2020]
num_books = [1000, 1500, 2000, 2500, 3000, 3500]
# 绘制折线图
plt.plot(years, num_books)
# 添加标题和轴标签
plt.title("Number of Books Published by Year")
plt.xlabel("Year")
plt.ylabel("Number of Books")
# 显示图形
plt.show()
```
直方图示例代码:
```python
import matplotlib.pyplot as plt
# 准备数据
prices = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
num_books = [500, 800, 1000, 1200, 1500, 1300, 1000, 700, 500, 300]
# 绘制直方图
plt.bar(prices, num_books)
# 添加标题和轴标签
plt.title("Number of Books by Price Range")
plt.xlabel("Price Range")
plt.ylabel("Number of Books")
# 显示图形
plt.show()
```
条形图示例代码:
```python
import matplotlib.pyplot as plt
# 准备数据
publishers = ["Publisher A", "Publisher B", "Publisher C", "Publisher D", "Publisher E"]
num_books = [1000, 1500, 2000, 2500, 3000]
ratings = [3.5, 4.0, 4.2, 4.5, 4.3]
# 绘制条形图
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
ax1.bar(publishers, num_books, color="blue")
ax2.plot(publishers, ratings, color="red")
# 添加标题和轴标签
ax1.set_title("Number of Books and Average Rating by Publisher")
ax1.set_xlabel("Publisher")
ax1.set_ylabel("Number of Books")
ax2.set_ylabel("Average Rating")
# 显示图形
plt.show()
```
树状图示例代码:
```python
import matplotlib.pyplot as plt
import squarify
# 准备数据
authors = ["Author A", "Author B", "Author C", "Author D", "Author E"]
ratings = [4.2, 3.9, 4.5, 4.1, 4.3]
# 绘制树状图
squarify.plot(sizes=ratings, label=authors, alpha=.7)
# 添加标题
plt.title("Author Ratings")
# 隐藏坐标轴
plt.axis('off')
# 显示图形
plt.show()
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)