当前位置:网站首页>Use Matplotlib to draw a line chart
Use Matplotlib to draw a line chart
2022-06-25 14:48:00 【HELLOWORLD2424】
Use matplotlib Draw a line
The following is the use of Python,matplotlib An example of drawing a line chart , Including subgraphs , Axis adjustment , All samples including label position adjustment , And notes , For your reference .
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator
df_loss_arm = pd.read_csv("./result/loss_arm.csv", header=None)
df_loss_arm = df_loss_arm.reset_index()
df_loss_arm = df_loss_arm.rename(columns={
"index": "epoch", 0: "loss"})
df_acc_arm = pd.read_csv("./result/acc_arm.csv", header=None)
df_acc_arm = df_acc_arm.reset_index()
df_acc_arm = df_acc_arm.rename(columns={
"index": "epoch", 0: "accuracy"})
df_result_arm = pd.merge(df_loss_arm, df_acc_arm, "inner", "epoch")
""" epoch loss accuracy 0 0 1.598689 0.100060 1 1 1.022335 0.229167 2 2 0.745279 0.225962 3 3 0.771946 0.404247 4 4 0.627058 0.567007 """
df_loss_x86 = pd.read_csv("./result/loss_x86.csv", header=None)
df_loss_x86 = df_loss_x86.reset_index()
df_loss_x86 = df_loss_x86.rename(columns={
"index": "epoch", 0: "loss"})
df_acc_x86 = pd.read_csv("./result/acc_x86.csv", header=None)
df_acc_x86 = df_acc_x86.reset_index()
df_acc_x86 = df_acc_x86.rename(columns={
"index": "epoch", 0: "accuracy"})
df_result_x86 = pd.merge(df_loss_x86, df_acc_x86, "inner", "epoch")
# Define the font style of the two drawing titles
title_font = {
'weight': 'bold', 'style': 'normal', 'size': 16}
# Defining subgraphs ,2 That's ok 1 Column
fig, axs = plt.subplots(nrows=2, ncols=1, figsize=(9, 12), dpi=300)
# Setting parameters of Figure 1
axs[0].set_title("ResNet Training Loss Curve", color="b", font=title_font)
axs[0].plot(df_result_arm["epoch"], df_result_arm["loss"], "r", label="Ascend910")
axs[0].plot(df_result_x86["epoch"], df_result_x86["loss"], "g", label="Tesla V100")
# Set up x The scope of the shaft 0-100
axs[0].set_xlim(0, 100)
# adjustment x Axis scale
# axs[0].set_xticks(np.linspace(0, 100, 11))
# Set the unit scale to 5
x_major_locator = MultipleLocator(5)
axs[0].xaxis.set_major_locator(x_major_locator)
axs[0].set_ylim(0., 2.)
axs[0].set_yticks(np.linspace(0, 2, 9))
axs[0].set_xlabel("Epoch")
axs[0].set_ylabel("Loss")
# Set the curve description label to be placed in the upper right corner
axs[0].legend(loc="upper left")
# Set grid machine style
axs[0].grid(True, linestyle='--', alpha=0.5)
axs[1].set_title("ResNet Training Accuracy Curve", color="b", font=title_font)
axs[1].plot(df_result_arm["epoch"], df_result_arm["accuracy"], "r", label="Ascend910")
axs[1].plot(df_result_x86["epoch"], df_result_x86["accuracy"], "g", label="Tesla V100")
axs[1].set_xlim(0, 100)
# axs[1].set_xticks(np.linspace(0, 100, 11))
x_major_locator = MultipleLocator(5)
axs[1].xaxis.set_major_locator(x_major_locator)
axs[1].set_ylim(0, 1)
axs[1].set_yticks(np.linspace(0, 1, 11))
axs[1].set_xlabel("Accuracy")
axs[1].set_ylabel("Loss")
axs[1].legend(loc="upper left")
axs[1].grid(True, linestyle='--', alpha=0.5)
plt.show()
Finally, the output effect .
边栏推荐
- 从408改考自主命题,211贵州大学考研改考
- Extend JS copy content to clipboard
- JS get the height and width corresponding to the box model (window.getcomputedstyle, dom.getboundingclientrect)
- [untitled]
- Partager les points techniques de code et l'utilisation de logiciels pour la communication Multi - clients socket que vous utilisez habituellement
- 【世界历史】第二集——文明的曙光
- HMS Core机器学习服务实现同声传译,支持中英文互译和多种音色语音播报
- JS component
- [deep learning] multi label learning
- JS Base64 Library Learning
猜你喜欢

2022年广东高考分数线出炉,一个几家欢喜几家愁

Build a minimalist gb28181 gatekeeper and gateway server, establish AI reasoning and 3D service scenarios, and then open source code (I)

当了六年程序员第一次搞懂微服务架构的数据一致性,真不容易

Report on Hezhou air32f103cbt6 development board

重磅!国产 IDE 发布,由阿里研发,完全开源!(高性能+高定制性)

合宙Air32F103CBT6开发板上手报告

【中国海洋大学】考研初试复试资料分享
![[try to hack] vulhub shooting range construction](/img/fc/6057b6dec9b51894140453e5422176.png)
[try to hack] vulhub shooting range construction

Jaspersoft studio installation

Shell array
随机推荐
Two methods to rollback the code in pycharm to the specified version (with screenshot)
Is it normal to dig for money? Is it safe to open a stock account?
How to choose a technology stack for web applications in 2022
移除区间(贪心)
Kubernetes understands kubectl/ debugging
[try to hack] vulhub shooting range construction
多张动图怎样合成一张gif?仅需三步快速生成gif动画图片
Explanation of dev/mapper
About reconnection of STM32 using lan8720a plug-in network cable
Application of TSDB in civil aircraft industry
Mysql database compressed backup_ Summary of MySQL backup compression and database recovery methods
[Ocean University of China] information sharing for the first and second examinations of postgraduate entrance examination
Gif动画怎么在线制作?快试试这款gif在线制作工具
Flexible layout (display:flex;) Attribute details
让PyTorch训练速度更快,你需要掌握这17种方法
'NVIDIA SMI' is not an internal or external command, nor is it a runnable program or batch file
Complete and detailed compilation of experimental reports
Haven't you understood the microservice data architecture transaction management +acid+ consistency +cap+base theory? After reading it, you can completely solve your doubts
What moment makes you think there is a bug in the world?
dev/mapper的解释