1
A
回答
1
from javax.swing import JButton, JFrame, JPanel, JLabel, JMenuBar
from java.awt import GridBagLayout,GridBagConstraints
from java.awt import BorderLayout as BorderLayout
from javax.swing import WindowConstants
from ptolemy import *
from ptolemy.plot import Plot as Plot
from RainfallAnalysis import RainfallAnalysis
from jarray import array;
class Histogram(Plot):
dataset = 0;
theJFrame = JFrame();
def __init__(self):
self.theJFrame.setSize(400, 350); #outer box
self.setSize(350, 300); #graph window
self.setButtons(True); #buttons to print, edit, etc.
self.setMarksStyle("none"); #do not show marks at points
##
# Draw a histogram.
# It is assumed that all bins are of equal size.
# @param name The name to give this histogram in the key
# @param xMin minimum of x-range covered by histogram
# @param xMax maximum of x-range covered by histogram
# @param y array of bin heights; length of array is used to give number of points
def drawHistogram(self,name, xMin, xMax,y):
binWidth = (xMax - xMin)/y.__len__();
self.setBars(binWidth,0.0);
self.setConnected(False); # do not join bars with a line
first = True;
self.setYLabel("Rain Measurement");
self.setXLabel("days");
for i in range(y.__len__()): #loop to add bars to plot
x = i
self.addPoint(self.dataset, x, y[i], not first);
first = False;
self.addLegend(self.dataset, name);
self.dataset = self.dataset+1;
def showIt(self):
gridbag = GridBagLayout();
c = GridBagConstraints();
self.theJFrame.getContentPane().setLayout(gridbag);
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 1;
gridbag.setConstraints(self, c);
self.theJFrame.getContentPane().add(self);
self.theJFrame.setVisible(True);
self.theJFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
if __name__ == '__main__':
h = Histogram();
rf = RainfallAnalysis();
min = rf.getMin();
max = rf.getMax();
data = rf.getData();
h.drawHistogram("rainfall",min,max,data);
h.showIt();
和数据仅仅是双数的数组。
相关问题
- 1. 如何在c中绘制直方图
- 2. 绘制直方图
- 3. 绘制直方图
- 4. 绘制直方图
- 5. 如何绘制图像的直方图?
- 6. 用python绘制直方图
- 7. 在直方图中使用qplot()绘制垂直峰值线R
- 8. 使用pyplot绘制直方图
- 9. 使用集群绘制直方图
- 10. 使用Python绘制直方图
- 11. 使用matplot.lib绘制直方图
- 12. 使用gnuplot绘制词频直方图
- 13. 如何绘制直方图的密度?
- 14. 在熊猫中绘制直方图
- 15. 在Python中绘制直方图
- 16. 在Matlab中并排绘制直方图
- 17. 在直方图中绘制NA计数
- 18. 在MatLab中绘制直方图
- 19. 如何在python中绘制RGB图像的3D直方图
- 20. 如何使用R在绘图上绘制直线?
- 21. 绘制一种直方图
- 22. 如何在R中绘制ggplot2中的堆积点直方图?
- 23. R plot:如何使用plot绘制水平线的直方图()
- 24. 如何绘制使用RGB像素值的直方图?
- 25. 如何使用EmguCV绘制直方图和C#
- 26. 使用映射函数在pandas列中绘制直方图
- 27. 如何在R中绘制3D叠加直方图?
- 28. 绘制垂直直方图C#
- 29. 如何使用bootstrap示例数据在spss中绘制直方图?
- 30. 如何使用GULFLY在JULIA中实现直方图绘制的精度