改写以下代码为python:figure %set(gcf,'visible','off') warning off all; Signal3=Signal2(1:length(Signal2),:); D11=Signal3(:,2); Y11=log(Signal3(:,3)); Y22=Signal3(:,8); Y22(find(isnan(Y22)==1)) = 0; [AX1,H11,H12]=plotyy(D11,Y11,D11,Y22); set(get(AX1(1),'Ylabel'),'string','log(Price)','color','k','Fontsize',8); set(get(AX1(2),'Ylabel'),'string','CCPI_q','color','k','Fontsize',8); step1=(max(D11)-min(D11))/5; TICK=[D11(1) D11(328) D11(529) D11(751) D11(987) D11(1220) D11(2492) D11(2698) D11(end)]; set(AX1(1),'ylim',[-4,10],'xlim',[min(D11),max(D11)],'Xtick',TICK,'Fontsize',8); set(AX1(2),'ylim',[0,max(Y22)],'xlim',[min(D11),max(D11)],'Xtick',TICK,'Fontsize',8); set(gca,'Xticklabel',datestr(TICK,'yyyy.mm.dd'),'Fontsize',8); tick2=(max(Y22)-0)/7; set(AX1(1),'Ytick',-4:2:10,'Ycolor','k'); set(AX1(2),'Ytick',0:tick2:(max(Y22)),'Ycolor','k'); ytick=get(AX1(2),'Ytick'); for i = 1:length(ytick) yticklabel{i} = sprintf('%.2f',ytick(i)); end set(AX1(2),'Yticklabel',yticklabel); set(H11,'linestyle','-','color','k','linewidth',1); set(H12,'linestyle','-','color','r','linewidth',1); set(gcf,'unit','centimeters','position',[0,0,32,11]) grid on q=q*100;
时间: 2023-08-06 09:11:32 浏览: 82
import matplotlib.pyplot as plt
import numpy as np
plt.figure()
plt.gca().set_visible(False)
plt.warning('off')
Signal3 = Signal2[:len(Signal2), :]
D11 = Signal3[:, 1]
Y11 = np.log(Signal3[:, 2])
Y22 = Signal3[:, 7]
Y22[np.isnan(Y22) == 1] = 0
fig, AX1 = plt.subplots()
H11, = AX1.plot(D11, Y11, color='k', linestyle='-', linewidth=1)
H12, = AX1.plot(D11, Y22, color='r', linestyle='-', linewidth=1)
AX1.set_ylabel('log(Price)', color='k', fontsize=8)
AX2 = AX1.twinx()
AX2.set_ylabel('CCPI_q', color='k', fontsize=8)
AX1.set_ylim(-4, 10)
AX2.set_ylim(0, max(Y22))
step1 = (max(D11) - min(D11)) / 5
TICK = [D11[0], D11[327], D11[528], D11[750], D11[986], D11[1219], D11[2491], D11[2697], D11[-1]]
AX1.set_xlim(min(D11), max(D11))
AX1.set_xticks(TICK)
AX1.set_xticklabels([str(d) for d in TICK], fontsize=8)
AX1.set_yticks(np.arange(-4, 12, 2))
AX2.set_yticks(np.arange(0, max(Y22), max(Y22) / 7))
ytick = AX2.get_yticks()
yticklabel = ['%.2f' % y for y in ytick]
AX2.set_yticklabels(yticklabel)
plt.grid(True)
plt.gcf().set_size_inches(32, 11)
q = q * 100
阅读全文