python - 在 Python 中更改名称的同时绘制一些图形
问题描述
我使用以下代码来绘制和保存 8 个数字。此代码不会一次显示所有 8 个数字。怎么做?因为现在我们应该关闭一个图形并出现另一个图形。
以及如何使用文件中的数据值为每个图形更改一次图形的名称和标题data
?例如Fig1: ng = 100
,Fig2: ng = 250
等等。100
并且250
是数据文件中的数据。
谢谢
row, uf, ng, Tg = np.genfromtxt('texdata.txt',unpack=True)
fig, (ax1) = plt.subplots(1)
for x in range(len(ng)):
for xx in range(1,819):
ET_list=[]
z_list=[]
for z in np.arange(1,7):
Ju = dfimppara.iloc[xx, 1]
Jl = dfimppara.iloc[xx, 2]
lim = Ju - Jl
if lim > 1:
pass
else:
if Ju<7:
ET_list.append(ET(xx, z, 100, 1e9, 1, ng[x], 0, Tg[x], 1))
z_list.append(z)
plt.plot(z_list, ET_list))
else:
pass
ax1.title.set_text('Fig 1: ng = 100 ') # we need to change this value for each figure and number of the figure
plt.savefig('Fig1:T_j.png') # number of the figure should change
plt.show()
解决方案
您可以使用f string
格式:
ax1.title.set_text(f'Fig {x}: TG = {Tg[x]}, ng = {ng[x]} ')
plt.savefig(f'Fig1:T_{x}.png')
假设ng
和x
是您要使用的值。
推荐阅读
- html - 什么是“动画”网站主题或设计?
- arrays - Angular 11 - 我的 highcharts 中的图例已分组,输出未显示
- foreach - Summernote 按钮在淘汰赛循环中不起作用
- javascript - 禁用存在于跨源 iframe 标记内的锚标记
- mysql - 如何形成只从两个链接表中选择第一个条目的查询?
- java - 使用JS在Thymeleaf中生成输入字段的id和name属性无效
- php - 如何在 PHP 中读取日期数据 excel?
- angular - Quilljs 中的印地语兼容性
- linux - 如何使用 socat 更新受限区域中的服务器?
- excel - 从启用宏的工作表创建数据透视表时,Mac Excel 崩溃