我有以下形式的数据框(约1万行):
id | voted
123 1.0
12 0.0
215 1.0
362 0.0
...
我想对此进行柱状图绘制,并查看值大部分为0.0的地方和值大部分为1.0的地方。 (第一列中的索引顺序是必不可少的,因为对数据框进行了排序)。
我尝试绘制条形图,但是即使我将自己限制在数据框的一小部分中,该图仍然不可读:
当将垃圾箱设置为更高或更低的数量时,是否有一种方法可以用单个较粗的条来近似显示大部分为1.0的区域?
答案 0 :(得分:0)
在搜索投票密度的区间近似值时,也许可以在其中添加moving average:
import java.util.Date;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
import org.activiti.engine.identity.User;
public class LdapClient {
public static void main(String[] args) {
System.out.println("run: " + new Date());
LdapContext ldapContext = getLdapContext();
SearchControls searchControls = getSearchControls();
getUserInfo("Mirko", ldapContext, searchControls);
System.out.println("done: " + new Date());
}
private static LdapContext getLdapContext() {
LdapContext ctx = null;
try {
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_AUTHENTICATION, "Simple");
env.put(Context.SECURITY_PRINCIPAL, "CN=Aleksandar Andric,CN=Users,DC=server,DC=net");//input user & password for access to ldap
env.put(Context.SECURITY_CREDENTIALS, "12Malloc3");
env.put(Context.PROVIDER_URL, "ldap://192.168.1.124:389");
env.put(Context.REFERRAL, "follow");
ctx = new InitialLdapContext(env, null);
System.out.println("LDAP Connection: COMPLETE");
} catch (NamingException nex) {
System.out.println("LDAP Connection: FAILED");
nex.printStackTrace();
}
return ctx;
}
private static User getUserInfo(String userName, LdapContext ctx, SearchControls searchControls) {
System.out.println("*** " + userName + " ***");
User user = null;
try {
NamingEnumeration<SearchResult> answer = ctx.search("DC=server,DC=net", "sAMAccountName=" + userName, searchControls);
if (answer.hasMore()) {
Attributes attrs = answer.next().getAttributes();
System.out.println(attrs.get("distinguishedName"));
System.out.println(attrs.get("givenname"));
System.out.println(attrs.get("sn"));
System.out.println(attrs.get("mail"));
System.out.println(attrs.get("userPassword"));
} else {
System.out.println("user not found.");
}
} catch (Exception ex) {
ex.printStackTrace();
}
return user;
}
private static SearchControls getSearchControls() {
SearchControls cons = new SearchControls();
cons.setSearchScope(SearchControls.SUBTREE_SCOPE);
String[] attrIDs = {"distinguishedName", "sn", "givenname", "mail", "telephonenumber", "thumbnailPhoto"};
cons.setReturningAttributes(attrIDs);
return cons;
}
}
使用此方法,您将始终具有平均值,然后可以将其作为线形图绘制在索引上,如果该值接近1,则说明您有一组ID投票为1.0。