網站首頁 編程語言 正文
實現了在一張圖片里用matplotlib的pyplot同時繪制折線圖和柱狀圖。以以下實現的代碼為例子
# -*- coding:utf-8 -*-
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
matplotlib.rcParams['font.sans-serif'] = ['SimHei'] # 用黑體顯示中文
# 構建數據
x = np.arange(1, 15)
y = [0.8, 0.88, 0.825, 0.76, 0.91, 0.95, 0.74, 0.99, 0.80, 0.72, 0.9, 0.81, 0.74, 0.87]
z = [37, 25, 17, 49, 27, 77, 34, 34, 34, 51, 39, 52, 47, 12]
u = [37, 31, 19, 57, 29, 86, 36, 37, 45, 64, 42, 57, 50, 24]
# 繪柱狀圖
plt.bar(x=x, height=z, label='實際', color='Coral', alpha=0.8)
plt.bar(x=x, height=u, label='總數', color='LemonChiffon', alpha=0.8)
# 在左側顯示圖例
plt.legend(loc="upper left")
# 設置標題
plt.title("Detection results")
# 為兩條坐標軸設置名稱
plt.xlabel("Component number")
plt.ylabel("Number of seam")
# 畫折線圖
ax2 = plt.twinx()
ax2.set_ylabel("recall")
# 設置坐標軸范圍
ax2.set_ylim([0.5, 1.05]);
plt.plot(x, y, "r", marker='.', c='r', ms=5, linewidth='1', label="Recall")
# 顯示數字
for a, b in zip(x, y):
plt.text(a, b, b, ha='center', va='bottom', fontsize=8)
# 在右側顯示圖例
plt.legend(loc="upper right")
plt.savefig("recall.jpg")
plt.show()
結果:
原文鏈接:https://blog.csdn.net/weixin_39589455/article/details/129160579
- 上一篇:沒有了
- 下一篇:沒有了
相關推薦
- 2023-02-05 c++?梅森數源碼示例解析_C 語言
- 2022-11-25 Python?Playwright的使用詳解_python
- 2022-07-23 Python實現單向鏈表_python
- 2022-08-01 C++簡單又輕松的講解類和對象中友元函數_C 語言
- 2022-06-11 在Docker容器中部署MSSQL_docker
- 2021-12-13 C語言數據結構與算法之圖的遍歷(一)_C 語言
- 2022-08-05 Python時間操作之pytz模塊使用詳解_python
- 2022-03-27 C語言中浮點數的精度丟失問題解決_C 語言
- 欄目分類
-
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支