一、当我们用Python matplot时作图时,一些数据需要以百分比显示,以更方便地对比模型的性能提升百分比。
二、借助matplotlib.ticker.FuncFormatter(),将坐标轴格式化。
例子:
# encoding=utf-8 import matplotlib.pyplot as plt from matplotlib.ticker import FuncFormatter plt.rcParams['font.family'] = ['Times New Roman'] plt.rcParams.update({'font.size': 8}) x = range(11) y = range(11) plt.plot(x, y) plt.show()
图形显示如下:
现在我们将横纵坐标变成百分比形式即,0%,20%,40%....代码如下:
# encoding=utf-8 import matplotlib.pyplot as plt from matplotlib.ticker import FuncFormatter plt.rcParams['font.family'] = ['Times New Roman'] plt.rcParams.update({'font.size': 8}) x = range(11) y = range(11) plt.plot(x, y) def to_percent(temp, position): return '%1.0f'%(10*temp) + '%' plt.gca().yaxis.set_major_formatter(FuncFormatter(to_percent)) plt.gca().xaxis.set_major_formatter(FuncFormatter(to_percent)) plt.show()
即增加了10~13的代码,执行结果如下:
可见已经实现我们的需求。
重要代码
return '%1.0f'%(10*temp) + '%' #这句话指定了显示的格式。
更多格式化显示,可以查看matplotlib.ticker。
补充知识:matplotlib画图系列之设置坐标轴(精度、范围,标签,中文字符显示)
在使用matplotlib模块时画坐标图时,往往需要对坐标轴设置很多参数,这些参数包括横纵坐标轴范围、坐标轴刻度大小、坐标轴名称等
在matplotlib中包含了很多函数,用来对这些参数进行设置。
plt.xlim、plt.ylim 设置横纵坐标轴范围
plt.xlabel、plt.ylabel 设置坐标轴名称
plt.xticks、plt.yticks设置坐标轴刻度
以上plt表示matplotlib.pyplot
例子
#导入包 import matplotlib.pyplot as plt import numpy as np #支持中文显示 from pylab import * mpl.rcParams['font.sans-serif'] = ['SimHei'] #创建数据 x = np.linspace(-5, 5, 100) y1 = np.sin(x) y2 = np.cos(x) #创建figure窗口 plt.figure(num=3, figsize=(8, 5)) #画曲线1 plt.plot(x, y1) #画曲线2 plt.plot(x, y2, color='blue', linewidth=5.0, linestyle='--') #设置坐标轴范围 plt.xlim((-5, 5)) plt.ylim((-2, 2)) #设置坐标轴名称 plt.xlabel('xxxxxxxxxxx') plt.ylabel('yyyyyyyyyyy') #设置坐标轴刻度 my_x_ticks = np.arange(-5, 5, 0.5) my_y_ticks = np.arange(-2, 2, 0.3) plt.xticks(my_x_ticks) plt.yticks(my_y_ticks) #显示出所有设置 plt.show()
结果
以上这篇使用Python matplotlib作图时,设置横纵坐标轴数值以百分比(%)显示就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
- 群星《前途海量 电影原声专辑》[FLAC/分轨][227.78MB]
- 张信哲.1992-知道新曲与精丫巨石】【WAV+CUE】
- 王翠玲.1995-ANGEL【新艺宝】【WAV+CUE】
- 景冈山.1996-我的眼里只有你【大地唱片】【WAV+CUE】
- 群星《八戒 电影原声带》[320K/MP3][188.97MB]
- 群星《我的阿勒泰 影视原声带》[320K/MP3][139.47MB]
- 纪钧瀚《胎教古典音乐 钢琴与大提琴的沉浸时光》[320K/MP3][148.91MB]
- 刘雅丽.2001-丽花皇后·EMI精选王【EMI百代】【FLAC分轨】
- 齐秦.1994-黄金十年1981-1990CHINA.TOUR.LIVE精丫上华】【WAV+CUE】
- 群星.2008-本色·百代音乐人创作专辑【EMI百代】【WAV+CUE】
- 群星.2001-同步过冬AVCD【环球】【WAV+CUE】
- 群星.2020-同步过冬2020冀待晴空【环球】【WAV+CUE】
- 沈雁.1986-四季(2012梦田复刻版)【白云唱片】【WAV+CUE】
- 纪钧瀚《胎教古典音乐 钢琴与大提琴的沉浸时光》[FLAC/分轨][257.88MB]
- 《国语老歌 怀旧篇 3CD》[WAV/分轨][1.6GB]