将图形存储在数组中

时间:2019-03-14 10:37:14

标签: julia plots.jl

我正在尝试在子图中绘制数据帧不同列的直方图。

plt_count = 1
for i = names(abalone)[2:end]
    p[plt_count]=histogram(abalone[:,i])
    plt_count += 1
end
plot(p, layout=(3,3), legend=false)

这是我尝试过的。但是我无法为数组p提出正确的定义。如何定义p?

代码的改进也将有所帮助。

1 个答案:

答案 0 :(得分:1)

如果您不关心类型稳定性,可以创建public abstract class Square { private String name; private boolean isAvailable; private Player owner; //getters and setters } public class Property extends Square{ private String colour; private int buyHouset; private int rent1House; private int rent2House; private int rent3House; private int rentHotel; private int numHouses; private int rent; private int price; //getters and setters } public static void takeTurn(Player player, Dice die, ArrayList<Square> board) { System.out.println(player.getGamertag() + "'s turn"); //get value from roll of die int move = askToRoll(); String gamertag = player.getGamertag(); //if player does not quit continue with turn if(move > 0) { //get player current position and add roll of die int newSpaceIndex = player.getPosition() + move; //if players new position exceeds the array of squares, return to 0 index and add remainder //add credits for passing Go //else update position if (newSpaceIndex > 11) { player.setPosition(newSpaceIndex - 12); Go.passGoAction(player); }else { player.setPosition(newSpaceIndex); } if(player.getPosition() == 1) { Square newPosition = board.get(player.getPosition()); System.out.println(gamertag + " new position " + newPosition.getName()); }else if(player.getPosition() == 6) { FreeParking.freeParkingAction(); } else { Square newPosition = board.get(player.getPosition()); System.out.println("____________________"); System.out.println("Land on " + newPosition.getName()); if(newPosition.getOwner() != null) { Player owner = newPosition.getOwner(); /* *****THIS IS WHERE THE ERROR IS STEMING FROM***** *THE newPosition.getRent() method can not be accessed as newPosition *is defines as Square */ System.out.println(owner.getGamertag() + " demands you pay " + newPosition.getRent() + " credits!"); }else { System.out.println("What would you like to do now? ...\n" + "1. Buy property\n" + "2. End turn"); int input = in.nextInt(); boolean valid = false; do { switch(input) { case 1: System.out.println("You now own controlling stock of " + newPosition.getName()); player.setOwnsProperty(newPosition); newPosition.setOwner(player); valid = true; break; case 2: System.out.println("Ending turn"); valid=true; break; default: System.out.println("Invalid input, please select one of the options 1-2"); valid = false; break; } }while(!valid); } } } System.out.println("END TURN: " + player); System.out.println(); } 类型数组。

Any

如果要专门创建ps = Array{Any}(nothing, 3) ps[1] = plot([2,3,4]) ps[2] = plot([1,5]) ps[3] = plot([10,5,1,0]) @show typeof(ps) plot(ps..., layout=(3,1)) 类型的数组,一种方法是使用虚拟图初始化数组,然后再替换。

Plot