我读从C++代码插座的消息,我试图以交互方式绘制它matplotlib,但它似乎Python代码会阻塞主线程,不管我用show()或ion()和draw().ion()并且draw()不会在Python中阻止.
知道如何matplotlib在C++代码中交互式绘制?
一个例子真的很好.
非常感谢.
可能重复:
通过NULL类指针调用类方法
#include <iostream>
using namespace std;
class test
{
int i;
public:
test():i(0){ cout << "ctor called" << endl;}
void show()
{
cout<<"show fun called"<<endl;
}
};
int main(int argc , char *argv[])
{
test *ptr = NULL;
ptr->show();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
很明显,没有人会被召唤.这是标准吗?或者只是一些编译器优化,因为这个指针没有在show()成员函数中使用?
我用g ++编译一个测试代码没有任何问题.
#include "Python.h"
int main(int argc, char** argv)
{
Py_Initialize();
PyRun_SimpleString("import pylab");
PyRun_SimpleString("pylab.plot(range(5))");
PyRun_SimpleString("pylab.show()");
Py_Exit(0);
}
Run Code Online (Sandbox Code Playgroud)
g++ -o test test.cpp -I/usr/include/python2.7/ -lpython2.7
工作正常,运行.
但是当我尝试将此代码嵌入到另一个项目中时,它会失败.这真让我困惑.
Makefile如下所示.
CXX=g++
CXXFLAGS=-DIB_USE_STD_STRING -Wall -Wno-switch -g
ROOT_DIR=..
BASE_SRC_DIR=${ROOT_DIR}/PosixSocketClient
INCLUDES=-I${ROOT_DIR}/Shared/ -I${BASE_SRC_DIR} -I/usr/include/python2.7
LIBRARY=-L/usr/lib/python2.7/config
TARGET=eu
$(TARGET):
$(CXX) $(CXXFLAGS) $(INCLUDES) -o EClientSocketBase.o -c $(BASE_SRC_DIR)/EClientSocketBase.cpp
$(CXX) $(CXXFLAGS) $(INCLUDES) -o EPosixClientSocket.o -c $(BASE_SRC_DIR)/EPosixClientSocket.cpp
$(CXX) $(CXXFLAGS) $(INCLUDES) -o PosixTestClient.o -c PosixTestClient.cpp
$(CXX) $(CXXFLAGS) $(INCLUDES) -o Main.o -c Main.cpp
$(CXX) $(LIBRARY) -lpython2.7 -o $@ EClientSocketBase.o EPosixClientSocket.o PosixTestClient.o Main.o
clean:
rm -f $(TARGET) …Run Code Online (Sandbox Code Playgroud) 我的数据框有不均匀的时间索引.
我怎样才能找到一种绘制数据的方法,并自动将索引本地化?我在这里搜索,我知道我可以画出类似的东西
e.plot()
Run Code Online (Sandbox Code Playgroud)

但是时间索引(x轴)将是偶数间隔,例如每5分钟.如果我在前5分钟内需要100个数据,在第二个5分钟内需要6个数据,我如何均匀地绘制数据数量.并在x轴上找到正确的时间戳.
这里甚至算,但我不知道如何添加时间指数.
plot(e['Bid'].values)
Run Code Online (Sandbox Code Playgroud)

请求的数据格式示例
次,bid
2014-03-05 21:56:05:924300,1.37275
2014-03-05 21:56:05:924351,1.37272
2014-03-05 21:56:06:421906,1.37275
2014-03-05 21:56:06:421950,1.37272
2014-03-05 21:56:06:920539,1.37275
2014-03-05 21:56:06:920580,1.37272
2014-03-05 21:56:09:071981,1.37275
2014-03-05 21:56:09:072019,1.37272
这里是链接 http://code.google.com/p/eu-ats/source/browse/trunk/data/new/eur-fix.csv
这是代码,我曾经用过
import numpy as np
import pandas as pd
import datetime as dt
e = pd.read_csv("data/ecb/eur.csv", dtype={'Time':object})
e.Time = pd.to_datetime(e.Time, format='%Y-%m-%d %H:%M:%S:%f')
e.plot()
f = e.copy()
f.index = f.Time
x = [str(s)[:-7] for s in f.index]
ff = f.set_index(pd.Series(x))
ff.index.name = 'Time'
ff.plot()
Run Code Online (Sandbox Code Playgroud)
更新:
我添加了两个新的图表进行比较以澄清问题.现在我尝试使用暴力将时间戳索引转换回字符串,并将字符串绘制为x轴.格式容易搞砸了.似乎很难定制x标签的位置.


我有一个熊猫系列.我需要得到sigma_i,这是索引i的系列的标准偏差.是否有任何有效计算的功能?
我注意到有cummax,cummin功能.
是否有类似以下的函数来创建具有十列Series s的数据框?
df = pd.DataFrame(s, 10)
Run Code Online (Sandbox Code Playgroud)
谢谢!
我知道这是可能的,有没有其他方法来传递像0:100这样的东西?
a=range(1000)
ohlc.C.ix[a]
Run Code Online (Sandbox Code Playgroud)
谢谢!
说我们有
Class A{};
int *p = malloc(100);
A a; //default constructor in use
*p = A; (question???)
Run Code Online (Sandbox Code Playgroud)
如何在alloc memory p上初始化类型A的对象?