Skip to content

Instantly share code, notes, and snippets.

@q8f13
Created January 12, 2024 11:38
Show Gist options
  • Save q8f13/11db0fd69a0342f02ae158f21ff201bc to your computer and use it in GitHub Desktop.
Save q8f13/11db0fd69a0342f02ae158f21ff201bc to your computer and use it in GitHub Desktop.
pyplot diagram generate
import matplotlib.pyplot as plt
import matplotlib.dates
import numpy as np
from random import random
from random import gauss
from random import uniform
from datetime import datetime
from datetime import timedelta
# GEO-08
val_base = 1.15
val_dir = 1.0
val_dt = 0.02
predict_num = 720
monitor_num = 2880
times = []
# data = [0.3, 0.5, 0.8, 1.4]
data = []
break_gap = [[180,280], [400,550], [2660,2730]]
DPI=96
# W=1220
W=950
# W=1141
# H=300
H=550
matplotlib.rc("font",family='DengXian')
fig=plt.figure(figsize=(W/DPI, H/DPI), dpi=DPI)
fig.patch.set_edgecolor('orange')
time_start = datetime(2020,1,19,0,0,0)
predict_start = datetime(2020,1,20,0,0,0)
t = time_start
data = []
data_predict = []
falloff = 0.999
# noise
mu = 0.0
sigma = 0.2
# data prepare
dp = []
count = 1440
for i in range(count):
val_to_push = np.nan
if random() < 0.2:
val_dir = val_dir * -1
if val_base < 0.1:
val_dir = 1
elif val_base > 2.1:
val_dir = -1
val_to_push = val_base + random()*val_dt*val_dir
val_base = val_to_push
dp.append(val_base)
offset = 0.0
idx = 0
t = time_start
for i in range(predict_num + monitor_num):
data.append((dp[idx] + gauss(mu, sigma)) + offset if i <= 2880 else np.nan)
data_predict.append(np.nan if (i <= 2880 or i > 3600) else (dp[idx] + gauss(mu, sigma) + offset))
idx=idx+1
if idx >= 1440:
idx = 0
offset = uniform(0.05, 0.08) * (1 if random() < 0.5 else -1)
t = t + timedelta(seconds=(30))
times.append(t)
# apply data gaps
for gap in break_gap:
for i in range(gap[0], gap[1]):
data[i] = np.nan
dates = matplotlib.dates.date2num(times)
mask = dates >= matplotlib.dates.date2num(predict_start)
plt.ticklabel_format(axis='y', style='plain', useOffset=False)
plt.plot_date(dates, data, c='#205b84', linewidth=1, linestyle='solid', marker=None, label="UERE监测数据")
plt.plot_date(dates, data_predict, c='#ffa500', linewidth=1, linestyle='solid', marker=None, label="UERE预测数据")
# plt.plot_date(dates, data, linewidth=2, linestyle='solid', markersize=3)
plt.legend(loc="upper right")
plt.gcf().autofmt_xdate()
plt.title('C37 MEO-18 2020/01/19-2020/01/20')
ax=plt.gca()
# ax.spines['bottom'].set_color('white')
# ax.spines['top'].set_color('white')
# ax.spines['left'].set_color('white')
# ax.spines['right'].set_color('white')
# ax.tick_params(axis='x', color='white', labelcolor='white')
# ax.tick_params(axis='y', color='white', labelcolor='white')
ax.xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%H:%M:%S'))
# fig.set_size_inch()
# plt.figure(figsize=(W/DPI, H/DPI))
plt.ylabel('UERE(m)')
# plt.subplots_adjust(top=0.4)
plt.show()
# plt.savefig('tmp.png', transparent = True, dpi=DPI)
import matplotlib.pyplot as plt
import matplotlib.dates
from random import random
from random import gauss
import numpy as np
from datetime import datetime
from datetime import timedelta
times = []
# data = [0.3, 0.5, 0.8, 1.4]
data = []
DPI=96
# W=1220
W=950
# W=1141
# H=300
H=550
num = 190
t_from = 11
# mu = 1.07e-5
# sigma = 0.8e-6
# sigma = 0.5 # standard deviation
mu = 3.45 # mean
sigma = 0.35
fig=plt.figure(figsize=(W/DPI, H/DPI), dpi=DPI)
fig.patch.set_edgecolor('orange')
except_idx = -1
# except_idx = num - int(random() * 15 + 110)
step = 240 / 190.0
val_raise = 0.2e-6
raise_falloff = 0.99
data_filtered = []
for i in range(num):
t = datetime(2023, 10, 31, 9, 0, 0)
t = t + timedelta(minutes=(i*step))
times.append(t)
# show_except = 0.0
# drop = 0.0
val = gauss(mu, sigma)
# if i == except_idx:
# val_raise += random() * 1.2
# val_raise += random() * 1.2e-7
# # show_except = (random()*4.0 + 5.0) if i == except_idx else 0.0
val = val + val_raise
# if val > 8.4:
data_filtered.append(val)
# else:
# data_filtered.append(np.nan)
data.append(val)
# data.append(max(0.25, gauss(mu, sigma)))
dates = matplotlib.dates.date2num(times)
plt.plot_date(dates, data, c='orange', linewidth=2, linestyle='solid', markersize=3)
# plt.plot_date(dates, data_filtered, c='orange', linewidth=2, linestyle='solid', markersize=6, markerfacecolor='red')
# plt.plot_date(dates, data, linewidth=2, linestyle='solid', markersize=3)
plt.gcf().autofmt_xdate()
ax=plt.gca()
ax.spines['bottom'].set_color('white')
ax.spines['top'].set_color('white')
ax.spines['left'].set_color('white')
ax.spines['right'].set_color('white')
ax.tick_params(axis='x', color='white', labelcolor='white')
ax.tick_params(axis='y', color='white', labelcolor='white')
# fig.set_size_inch()
# plt.figure(figsize=(W/DPI, H/DPI))
# plt.ylabel('some numbers')
# plt.subplots_adjust(top=0.4)
# plt.show()
plt.savefig('tmp.png', transparent = True, dpi=DPI)
import matplotlib.pyplot as plt
import matplotlib.dates
import numpy as np
from random import random
from random import gauss
from datetime import datetime
from datetime import timedelta
# GEO-08
sim_data = [
[884.570836,884.569775,884.56853,884.56733,884.566245,884.564984,884.563797,884.562559,884.561525,884.56031,884.559162,884.558044,884.556892,884.555824,884.554648,884.553681,884.552596,884.55162,884.550716,884.549779,884.548738,884.547762,884.546776,884.546126],
[884.5692361593246, 884.5681689977646, 884.5671019554138, 884.5660347938538, 884.5649675130844, 884.5639003515244, 884.5628333091736, 884.5617661476135, 884.5606988668442, 884.5596318244934, 884.5585646629333, 884.5574975013733, 884.5564304590225, 884.5553631782532, 884.5542960166931, 884.5532289743423, 884.552161693573, 884.5510946512222, 884.5500274896622, 884.5489604473114, 884.547893166542, 884.5468261241913, 884.5457589626312, 884.5446919202805],
[884.56766,884.566634, 884.565507,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan]
# [884.56766,884.566634,884.565507,884.564484,884.563454,884.562423,884.561388,884.560346,884.559307,884.558277,884.557246,884.556226,884.555229,884.554226,884.553243,884.552256,884.551281,884.550312,884.549356,884.548388,884.547429,884.546476,884.545521,884.544601],
]
times = []
# data = [0.3, 0.5, 0.8, 1.4]
data = []
DPI=96
# W=1220
W=950
# W=1141
# H=300
H=550
num = 190
t_from = 11
mu = 1.07e-5
sigma = 0.8e-7
# sigma = 0.5 # standard deviation
# mu = 3.45 # mean
# sigma = 0.5
matplotlib.rc("font",family='DengXian')
fig=plt.figure(figsize=(W/DPI, H/DPI), dpi=DPI)
fig.patch.set_edgecolor('orange')
except_idx = int(random() * 15 + 70)
time_start = datetime(2023,7,14,0,0,0)
count = len(sim_data[0])
# days = 15
step = 16.0 / count
for i in range(count):
# t = datetime(2023, 10, 31, 9, 0, 0)
t = time_start
t = t + timedelta(hours=(i * round(24 * step)))
times.append(t)
# show_except = 0.0
# drop = 0.0
# if i == except_idx:
# # show_except = (random()*4.0 + 5.0) if i == except_idx else 0.0
# data.append(1.22e-5)
# else:
# data.append(gauss(mu, sigma))
# data.append(max(0.25, gauss(mu, sigma)))
dates = matplotlib.dates.date2num(times)
plt.ticklabel_format(axis='y', style='plain', useOffset=False)
plt.plot_date(dates, sim_data[0], c='blue', linewidth=2, linestyle='solid', marker=None, label="真值")
plt.plot_date(dates, sim_data[2], c='green', linewidth=2, linestyle='solid', marker=None, label="igmas")
plt.plot_date(dates, sim_data[1], c='orange', linewidth=2, linestyle='solid', marker=None, label="预测")
# plt.plot_date(dates, data, linewidth=2, linestyle='solid', markersize=3)
plt.legend(loc="upper right")
plt.gcf().autofmt_xdate()
plt.title('C01 GEO-08 2023/7/14-2023/7/29')
# ax=plt.gca()
# ax.spines['bottom'].set_color('white')
# ax.spines['top'].set_color('white')
# ax.spines['left'].set_color('white')
# ax.spines['right'].set_color('white')
# ax.tick_params(axis='x', color='white', labelcolor='white')
# ax.tick_params(axis='y', color='white', labelcolor='white')
# fig.set_size_inch()
# plt.figure(figsize=(W/DPI, H/DPI))
# plt.ylabel('some numbers')
# plt.subplots_adjust(top=0.4)
plt.show()
# plt.savefig('tmp.png', transparent = True, dpi=DPI)
import matplotlib.pyplot as plt
import matplotlib.dates
from random import random
from random import gauss
import numpy as np
from datetime import datetime
from datetime import timedelta
times = []
# data = [0.3, 0.5, 0.8, 1.4]
data = []
DPI=96
# W=1220
# W=950
W=821
# W=1141
# H=300
H=370
num = 200
# mu = 1.07e-5
# sigma = 0.8e-6
# sigma = 0.5 # standard deviation
mu = 8.1e-3 # mean
sigma = 2.15e-3
matplotlib.rc("font",family='Microsoft YaHei')
fig=plt.figure(figsize=(W/DPI, H/DPI), dpi=DPI)
fig.patch.set_edgecolor('orange')
# except_idx = -1
except_idx = int(num * 0.5) - int(random() * 5)
step = 2
for i in range(num):
t = datetime(2023, 11, 21, 9, 31, 0)
t = t + timedelta(seconds=(i*step))
times.append(t)
# show_except = 0.0
# drop = 0.0
if i > except_idx:
val = gauss(-mu, sigma)
else:
val = gauss(mu, sigma)
# val_raise += random() * 1.2
# val_raise += random() * 1.2e-7
# # show_except = (random()*4.0 + 5.0) if i == except_idx else 0.0
data.append(val)
# data.append(max(0.25, gauss(mu, sigma)))
dates = matplotlib.dates.date2num(times)
plt.title("钟差趋势", color='white')
plt.plot_date(dates, data, linewidth=1, linestyle='solid', markersize=0)
# plt.plot_date(dates, data_filtered, c='orange', linewidth=2, linestyle='solid', markersize=6, markerfacecolor='red')
# plt.plot_date(dates, data, linewidth=2, linestyle='solid', markersize=3)
plt.gcf().autofmt_xdate()
ax=plt.gca()
plt.ticklabel_format(axis='y', style='sci', scilimits=(0,0))
ax.spines['bottom'].set_color('white')
ax.spines['top'].set_color('white')
ax.spines['left'].set_color('white')
ax.spines['right'].set_color('white')
ax.tick_params(axis='x', color='white', labelcolor='white')
ax.tick_params(axis='y', color='white', labelcolor='white')
# fig.set_size_inch()
# plt.figure(figsize=(W/DPI, H/DPI))
plt.ylabel('钟差 (ms)', color='white')
# plt.subplots_adjust(top=0.4)
# plt.show()
plt.savefig('tmp.png', transparent = True, dpi=DPI)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment