在绘制一些点时,matplotlib
我在创建图形时遇到了一些奇怪的行为.以下是生成此图表的代码.
import matplotlib.pyplot as plt
desc_x =[4000,3000,2000,2500,2750,2250,2300,2400,2450,2350]
rmse_desc = [.31703 , .31701, .31707, .31700, .31713, .31698, .31697, .31688, .31697, .31699]
fig = plt.figure()
ax = plt.subplot(111)
fig.suptitle('title')
plt.xlabel('x')
plt.ylabel('y')
ax.plot(desc_x, rmse_desc, 'b', label='desc' )
ax.legend()
plt.show()
Run Code Online (Sandbox Code Playgroud)
这是它创建的图表
如您所知,此图形具有相交线,这是线图中看不到的.当我隔离点,并且不绘制线条时,我得到了这个结果:
如您所知,有一种方法可以连接这些点而不相交线.
为什么matplotlib这样做?我想我可以通过不对我的xcolumn进行排序来修复它,但如果我对它进行排序,我将失去从x1到y1的映射.
我试图循环一些json文件,并将它们组合成一个json文件.我的计划是拥有一个全局$allData
数组,并将新的候选者合并到它们中.
<?php
$allData = array();
$count = 0;
if ($handle = opendir('./json/')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
echo $entry."<br />";
$source_file = file_get_contents('./json/'.$entry);
$data = json_decode($source_file,TRUE);
if($data != null){
$allData = array_merge($allData,$data);
echo "<br /><br /><br /><br /> !!!! <br /><br /><br /><br />";
print_r($allData);
}
else{
echo "Invalid Json File";
} //end else
}
closedir($handle);
}
echo "<br /><br /><br /><br /> !!!! <br /><br …
Run Code Online (Sandbox Code Playgroud) 这是我的代码:
public static void main(String args[]) throws Exception
{
BufferedReader infile = new BufferedReader(new FileReader(args[0]));
HashMap<String,Integer> histogram = new HashMap<String,Integer>();
while ( infile.ready() )
{
String SPACE = " ";
String [] words = infile.readLine().split(SPACE);
for (String word : words)
{
Integer f = histogram.get(word);
histogram.put(word,f+1);
}
}
infile.close();
printHistogram( histogram );
}
private static void printHistogram( HashMap<String,Integer> hm )
{
System.out.println(hm);
}
Run Code Online (Sandbox Code Playgroud)
我一直得到"histogram.put(word,f + 1);"的NullPointerException.部分.为什么是这样?
这是我的上下文文件:
<beans default-lazy-init="true" xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"> <!--Line 11-->
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <!---->
<property name="driverClassName" value="org.hsqldb.jdbc.JDBCDriver"/>
<property name="url" value="jdbc:hsqldb:mem:mydb"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="hibernate.cfg.xml.incDTD"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.connection.shutdown">true</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<jdbc:embedded-database id="embedded" type="HSQL"/>
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="classpath:ctl_data-scrubd.sql"/>
</jdbc:initialize-database>
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 11 in XML …
Run Code Online (Sandbox Code Playgroud) 我正在使用Hibernate 3和Spring 3.我一直在尝试填充内存数据库,我正在使用Spring这样做.当我尝试这样做时,我会感到非常沮丧,并且这个堆栈跟踪:为了节省你们一些阅读,例外是:
user lacks privilege or object not found: XFC_ACTIONSTARTCONDITIONTYPE
Failed to execute database script; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement at line 1 of resource class path resource [ctl_data-scrubd.sql]: INSERT INTO xfc_ActionStartConditionType (actionStartConditionTypeId,actionStartConditionTypeName) VALUES ('1','Start After Action Completed')" type="org.springframework.dao.DataAccessResourceFailureException">org.springframework.dao.DataAccessResourceFailureException: Failed to execute database script; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement at line 1 of resource class path resource [ctl_data-scrubd.sql]: INSERT INTO xfc_ActionStartConditionType (actionStartConditionTypeId,actionStartConditionTypeName) VALUES ('1','Start After Action Completed')
at org.springframework.jdbc.datasource.init.DatabasePopulatorUtils.execute(DatabasePopulatorUtils.java:57) …
Run Code Online (Sandbox Code Playgroud) 我在Java中有以下类.我希望能够将它保存为一个通用的文件格式,可以在不同的PC上移动.我知道对象序列化但我想知道我的其他选择是什么以及它们各自的优缺点是什么.谢谢!例如,序列化文件不是人类可读的,因此是骗局.
public class NervousSystem {
private CentralNervousSystem CNS;
private PeripheralNervousSystem PNS;
public NervousSystem(Neocortex neocortex, LateralGeniculateNucleus LGN, Retina retina) {
this.CNS = new CentralNervousSystem(neocortex, LGN);
this.PNS = new PeripheralNervousSystem(retina);
}
public CentralNervousSystem getCNS() {
return this.CNS;
}
public PeripheralNervousSystem getPNS() {
return this.PNS;
}
}
Run Code Online (Sandbox Code Playgroud) 从ant文件构建这个项目后,我收到一个包含我构建的所有类的jar.当我尝试运行此jar时,出现以下错误:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/media/j3d/SceneGraphObject
Run Code Online (Sandbox Code Playgroud)
此错误表示j3dcore.jar
无法找到其中一个罐子,特别是来自java3d 的罐子.但是,通过将ant构建编译到类文件中时,此jar位于类路径中.
为什么在运行时找不到这个类,但是在编译时可以找到它?在运行jar时我是否必须在shell中手动更改我的类路径以及在ant构建中更改它?
如果我使用jar将jar添加到我的类路径中 java -cp j3d/*.jar -jar idv.jar
我收到了错误 Error: Could not find or load main class j3d.j3dutils.jar
如果我有以下情况:
public class Foo extends Baz{
private String banana = "banana";
//blah blah blah
}
public class Baz{
protected static String apple = "apple";
}
Run Code Online (Sandbox Code Playgroud)
哪个先创建,苹果还是香蕉?我想说苹果首先被创造,但我不确定.
我最近写了一个涉及套接字的简单c ++程序.自从我使用c ++以来已经有一段时间了,所以我正在做一些简单的健全性检查,以确保我的类正确构建.那时我遇到了一个非常奇怪的错误.当我没有\n
或endl
在我的输出结束时,它不会写入控制台.例如:
这不会输出到控制台
class Server{
public:
Server(){
std::cout << "STARTING SERVER";
}
};
Run Code Online (Sandbox Code Playgroud)
这个会:
class Server{
public:
Server(){
std::cout << "STARTING SERVER" << std::endl;
}
};
Run Code Online (Sandbox Code Playgroud)
两者都是使用Server server;
.这只是我电脑里的"幽灵"还是以前有人遇到过这个?
我有一个Perl脚本,可以从Web表单中读取一些信息.为了做适当的卫生,我想使用这里system
描述的语法.
他们建议你应该用以下形式形成系统命令,system ("cat", "/usr/stats/$username");
这样username变量才会被解释为cat的参数.
如果我的命令的形式system("export REPLYTO=\"$from\"; echo \"$body\" | mail -s \"$subject\"");
有多个系统命令,我该如何正确清理系统调用?
java ×6
arrays ×2
hibernate ×2
junit ×2
spring ×2
ant ×1
c++ ×1
compile-time ×1
constructor ×1
file ×1
file-io ×1
hashmap ×1
hierarchy ×1
inheritance ×1
input ×1
java-3d ×1
json ×1
matplotlib ×1
merge ×1
newline ×1
numpy ×1
perl ×1
php ×1
plot ×1
python ×1
runtime ×1
sanitization ×1
save ×1
spring-test ×1
stdout ×1
system ×1