使用相同的时间轴绘制2个子图的垂直线

时间:2017-11-21 20:52:17

标签: python python-3.x plot

我是编程的新手,我一直在尝试使用不同功能的日子来绘制两个子图上的两条垂直线,它们共享x轴的时间但是有一个完全不同的y轴,但是这两条线都是' t出现在图表上或整个图表变空。 这些线应代表雷暴的开始和结束,因此它们应位于特定时间,在这种情况下为16:00和20:30。我必须为其他3个雷暴重复这个,我甚至无法做到一个。 我的代码就是:

ce28 = pd.read_csv('Data Source 1-06282017.efm', header=None, 
parse_dates=True)
col=ce28[1]
cuentas = 120
promedios = [sum(col[i:i+cuentas])//cuentas for i in range(0,len(col),cuentas)]

proms=promedios[924:]
print(len(proms))

from datetime import datetime
from datetime import timedelta

inicio = datetime(2017,6,28,14,0,0)
fin = datetime(2017,6,28,23,0,0)

seconds = (fin - inicio).total_seconds()
delta = timedelta(minutes=1)

tiempo = []
for i in range(0, int(seconds), int(delta.total_seconds())):
tiempo.append(inicio + timedelta(seconds=i))

print(len(tiempo))

datos= pd.read_csv('28-6-2017_28-6-2017_min.txt', sep='\t', header=None, 
parse_dates=True)
col1=datos[2]
col11=col1[900:]
print(len(col11))

fig1 = plt.figure(figsize=(25,8))
gs = gridspec.GridSpec(2, 1) 

ax0 = plt.subplot(gs[0])
graf0 = ax0.plot(tiempo, proms,color='b')
plt.ylabel('Intensidad de E (kV/m)',fontweight='bold')
plt.grid(True)
ax1 = plt.subplot(gs[1], sharex = ax0)
graf1 = ax1.plot(tiempo, col11, color='b')
plt.xlabel('Tiempo Local',fontweight='bold')
plt.ylabel('Cuentas por minuto',fontweight='bold')
plt.grid(True)
ax1.xaxis.set_major_locator(md.MinuteLocator(byminute=[0,15,30,45],interval=1))
ax1.xaxis.set_major_formatter(md.DateFormatter('%H:%M')) 
plt.ylim(1300,1450)
plt.setp(ax0.get_xticklabels(), visible=False)
plt.subplots_adjust(hspace=.0)
plt.margins(x=0)
plt.show()

这给出了这个漂亮的图表: beauty

我想要实现的是这样的,我用功率点绘制线条,显然质量不一样: desired

您可以给我的任何帮助将非常感谢!谢谢。

数据:https://www.dropbox.com/sh/cjolnsns37r8sby/AAAiijE3DWR1yR0G1qys7g47a?dl=0

3 个答案:

答案 0 :(得分:0)

这样的事情应该这样做

f = plt.figure()
ax1 = f.add_subplot(211)
ax2 = f.add_subplot(212)

rect = patches.Rectangle((10,2),3,1,linewidth=1,edgecolor='r',facecolor='none')

f.patches.extend([patches.Polygon([(0.4,0.1),(0.4,1.5)],
                                  fill=True, color='g', alpha=0.5, zorder=1000,
                                  transform=ax2.transData,
                                  figure=f)])

注意,线(polyon)的坐标是指ax2的数据空间。

enter image description here

答案 1 :(得分:0)

主要变化涉及red_ordinates。我还在上图中添加了y轴的限制。 x轴的刻度标签很乱。我希望这是因为我编制了数据并且没有花时间正确地完成它们。我的主要目的是建议一种获得垂直线的方法。

主要思想是,由于tiempo是日期时间单位,要绘制垂直线,它们的x坐标也必须是日期 - 时间单位;因此,计算和使用red_ordinates的方式。

from matplotlib import pyplot as plt
from matplotlib import gridspec
import matplotlib.dates as md
import numpy as np
import random

tiempo = np.arange(771).astype('<i8').view('M8[m]').tolist()
proms = [random.gauss(0,1) for _ in range(len(tiempo))]
col11 = [1380+5*random.gauss(0,1) for _ in range(len(tiempo))]

red_ordinates = np.linspace(10,50,2).astype('<i8').view('M8[m]').tolist()

fig1 = plt.figure(figsize=(25,8))
gs = gridspec.GridSpec(2, 1) 

ax0 = plt.subplot(gs[0])
graf0 = ax0.plot(tiempo, proms,color='b')

ax0.plot([red_ordinates[0], red_ordinates[0]], [-3.5, 3.5], color='r')
ax0.plot([red_ordinates[1], red_ordinates[1]], [-3.5, 3.5], color='r')

plt.ylim(-3.5, 3.5)
plt.ylabel('Intensidad de E (kV/m)',fontweight='bold')
plt.grid(True)
ax1 = plt.subplot(gs[1], sharex = ax0)
graf1 = ax1.plot(tiempo, col11, color='b')

ax1.plot([red_ordinates[0], red_ordinates[0]], [1300, 1450], color='r')
ax1.plot([red_ordinates[1], red_ordinates[1]], [1300, 1450], color='r')

plt.xlabel('Tiempo Local',fontweight='bold')
plt.ylabel('Cuentas por minuto',fontweight='bold')
plt.grid(True)
ax1.xaxis.set_major_locator(md.MinuteLocator(byminute=[0,15,30,45],interval=1))
ax1.xaxis.set_major_formatter(md.DateFormatter('%H:%M')) 
plt.ylim(1300,1450)
plt.setp(ax0.get_xticklabels(), visible=False)
plt.subplots_adjust(hspace=.0)
plt.margins(x=0)
plt.show()

结果情节:

plot

答案 2 :(得分:0)

这最终对我有用:

Print emptyIsAlwaysNil.

emptyIsAlwaysNil = 
fun a : bits 0 =>
match
  a as a0 in (bits n)
  return
    (match n as x return (bits x -> Type) with
     | 0 => fun a1 : bits 0 => a1 = bitsNil
     | S n0 => fun _ : bits (S n0) => IDProp
     end a0)
with
| bitsNil => eq_refl
| bitsCons _ _ => idProp
end
     : forall a : bits 0, a = bitsNil
相关问题