Python 如何从matplotlib中的hdf5文件格式打印选定的线
matplotlib中的子代码是Python 如何从matplotlib中的hdf5文件格式打印选定的线,python,matplotlib,Python,Matplotlib,matplotlib中的子代码是 from matplotlib import pyplot as plt lbl = {0:'AB', 1:'BC', 2:'CD', 3:'fourth'} for i, section in enumerate(dist): for nbnd, _ in enumerate(freq[i][0]): x = section # to_list() you may need to convert sample to list.
from matplotlib import pyplot as plt
lbl = {0:'AB', 1:'BC', 2:'CD', 3:'fourth'}
for i, section in enumerate(dist):
for nbnd, _ in enumerate(freq[i][0]):
x = section # to_list() you may need to convert sample to list.
y = (freq[i, :, nbnd] + offset*nbnd) * scale
if (nbnd<3):
color=f'C{nbnd}'
else:
color='black'
ax.plot(x, y, c=color, lw=2.0, alpha=0.8, label = lbl[nbnd] if nbnd < 3 and i == 0 else None)
ax.legend()
从matplotlib导入pyplot作为plt
lbl={0:'AB',1:'BC',2:'CD',3:'fourth'}
对于i,枚举(dist)中的部分:
对于nbnd,在枚举中(freq[i][0]):
x=部分#到_list(),您可能需要将示例转换为列表。
y=(频率[i,:,nbnd]+偏移量*nbnd)*刻度
if(nbnd它正在打印所有数据,因为您的plot命令不在if(nbndIt解决了一部分问题。我的第二部分是:如何控制与这三个绘图相关联的标签的大小(nbnd<3)?如lbl={0:'AB',1:'BC',2:'CD',3:'fourth'所定义的那样}@Asha:标签的大小是什么意思?如fontsize?@Asha堆栈溢出问题一次只能包含一个问题。我建议就标签的大小单独问另一个问题,并通过接受答案来标记此问题,如果它解决了您的问题,我将标签限制到每一行(如图左上角所示,这里有三个问题:我想增加/减少或重新定位绘图中的位置。问题是我不能在90分钟前提问,所以我在一篇帖子中添加了两个问题。希望你能理解。
if (nbnd<3):
color=f'C{nbnd}'
ax.plot(x, y, c=color, lw=2.0, alpha=0.8, label = lbl[nbnd] if nbnd < 3 and i == 0 else None)
plt.legend(loc=(0.5, 0.7), fontsize=20)