我试图拍摄许多xz图,每个图都有不同的y值,并覆盖表面.我已经看过很多关于如何在python中绘制3D曲面的例子,但除了这篇文章之外,似乎没有什么比我的查询更接近.
我需要做的图像如下所示(注意:忽略"常数x" - 这是由于比我在这里解释的更复杂的变量布局):
我的代码如下,并简单地获取数据并绘制每个单独的幅度与频率图(xz图):
import numpy as np
import glob, os
import codecs
import re
import matplotlib.pyplot as plt
#-------------------------------------------------------------------------
os.chdir('C:/Users/elarrick/Desktop/201807161056')
dataFolders = glob.glob('./*.ltda')
dataLines = []
freq = []
OpenLoopMag = []
OpenLoopPhase = []
for item in dataFolders:
name, ext = os.path.splitext(item)
if ext == '.ltda':
print item
dataLines = []
f = codecs.open(item, encoding='utf-8')
for line in f:
if '<p>' in line:
dataLines.append(line) #All …Run Code Online (Sandbox Code Playgroud) 我找到了几种将 Integer 和 Float 值转换为二进制的方法,它们各有各的问题。我需要在 0 和 10,000 的值之间输入一个整数/浮点数,转换为16 位(精确)二进制字符串,随机操作这些位,然后转换回整数/浮点数(取决于参数)。
但是,我一直在使用以下代码:
def convert_to_binary(value):
'''
Converts a float to a 16-bit binary string.
'''
[d] = struct.unpack('>Q', struct.pack('>d', value))
return str('{:016b}'.format(d))
def convert_back(bin_num):
'''
Converts binary string to a float.
'''
print type(bin_num)
print bin_num
bf = int_to_bytes(int(bin_num, 2), 8) # 8 bytes needed for IEEE 754 binary64.
print struct.unpack('>d', bf)[0]
return struct.unpack('>d', bf)[0]
# return struct.unpack('d', struct.pack('Q', bin_num))[0]
#bin_num.pack('B*').unpack('g').first
def int_to_bytes(n, minlen=0): # Helper function
''' …Run Code Online (Sandbox Code Playgroud)