Archive for category Graphing

A brand new version of eDigitizer with improved functions

Since the eDigitizer 2.0 released in a couple of year ago, new functions were requested and fulfilled. Some minor bugs were fixed. Now it is time to announce that a brand new version 2.10 is released. The new version brings the following new functions to the application.

  1. The linear distance of each segment is calculated and added together. This is the total distance between the first and last points. When you save the digitized data to file, you automatically get the points and the distances.
  2. Draw markers and line segments between adjacent points. That will help user to keep track of what is digitized and how good he does the job.

The following functions are either fixed or enhanced.

  1. The image can be restored by clicking the restore button. After the image is restored to its original, all line segments and point markers on the image will disappear.
  2. When you load a new image, all digitized information (data) will be cleaned. So make sure to save your digitized data before you do that.
  3. Save image function will save the image plus the point markers and line segments. So be careful that you do not overwrite the original image.
  4. During the digitizing period and after axes are digitized, you should not switch between two different size modes. if you do, the digitized data will be messed up.

The new version need .Net 2.0 and above framework to run. It can be used in Windows XP, Windows Vista, and Windows 7 etc.

To get the new release, just simply download the zip file and unpacked files into a folder; double click the eDigitizer application file; you can run the application right way.

Here is a snapshot for you to view.

Download the new release: eDigitizer210

Reference

Share

Tags: , , , , , ,

Display stock charts on your own website

Plain stock chart
In searching an easy way to display stock charts on a web page hosted in a web server, two useful scripts were found on the internet:

1. Easy Yahoo stock chart ASP.NET Page
2. Displaying a daily chart for a ticker symbol

Even the scripts were written in different languages, they use a common idea that fetch the Yahoo stock charts and display them locally. The first article gives a basic framework to do this in PHP. It has one missing statements at the beginning of the script. I added that and use the Yahoo link from the second article. Now this script can show 6 months and 3 months and daily chart at once.

<?php
//stock chart shower
//Beginners PHP
//Description : This allows a user to enter a ticker symbol
//and rather than the usual dry quotes displays a chart of
//how the stock has performed over the whole year

$symbol=$_POST['symbol'];

if ($symbol =="")
{
?>
<html><body>
<form action='<?php print $PHP_SELF; ?>' method ='post'>
Enter your ticker symbol :<input type='text' name='symbol' size = 6><br>
<input type='submit' value="show chart">
</form>
</body></html>
<?php
}
else
{
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="image/gif; charset=iso-8859-1">
</head>
<img border="0" src="http://ichart.finance.yahoo.com/z?s=<?php print $symbol; ?>&t=6m&q=c&l=on&z=l&a=v&p=s">
<img border="0" src="http://ichart.finance.yahoo.com/z?s=<?php print $symbol; ?>&t=3m&q=c&l=on&z=m&a=v&p=s">
<img border="0" src="http://ichart.yahoo.com/t?s=<?php print $symbol; ?>">

</body>
</html>
<?php
}
?>

Flash Stock Chart

Open Flash Chart 2 provides a whole library of PHP, PERL, Python, .NET and more languages that help your generate SWF flash charts for free. On its website, there are tons of examples to help you use the library. OFC2 uses JSON as the file format and you can generate cool chart in very short time.

The PHP source code to get data from database and generate JSON file for SWF chart is listed here.

<?php

include_once 'php-ofc-library/open-flash-chart.php';
include_once '../stocks_secureinfo.inc';

$stock_tick = 'LIWA';

$sql = " SELECT price_open, price_high, price_low, price_close, stock_volume, c_year, c_month, c_day from stockdata s ".
" INNER JOIN company c ON s.id_company=c.id_company ".
" INNER JOIN caldate d ON s.id_caldate=d.id_caldate ".
" WHERE c.tick='$stock_tick' ".
" ORDER BY c_year ASC, c_month ASC, c_day ASC ".
" ; ";
$result = mysql_query($sql);

if (!$result) {
die('Invalid query: ' . mysql_error());
}

$data = array();
$volume = array();
$max = 0;
while($row = mysql_fetch_array($result))
{
//
// LOOK: PHP thinks our data is text,
//       force it to be an integer:
//
$data[] = new candle_value(
(float)$row['price_high'],
(float)$row['price_open'],
(float)$row['price_close'],
(float)$row['price_low']);

$volume[] = (float)$row['stock_volume'];

}

$title = new title( $stock_tick );

### Candle graph for stock price
$candle = new candle('#9933CC');
$candle->set_values($data);
$candle->set_tooltip('#x_label#<br>High: #high#<br>Open: #open#<br>Close: #close#<br>Low: #low#');
//$candle->set_on_show(new bar_on_show('drop', .9, 0));

$y = new y_axis();
$y->set_range( 0, 11, 0);

$chart = new open_flash_chart();
$chart->set_title( $title );
$chart->add_element( $candle );
$chart->set_y_axis( $y );

### bar graph for stock volume
$bar = new bar();
$bar->set_values( $volume );
$bar->axis = 'right';

$yr = new y_axis_right();
$yr->set_range( 0, 2000000, 0);

$chart->add_element( $bar );
$chart->set_y_axis_right( $yr );

#echo $chart->toPrettyString();
write2file($chart->toPrettyString(),$stock_tick."_price.json");

function write2file($str,$filename)
{
$fh = fopen($filename, 'w') or die("can't open file");
fwrite($fh, $str);
fclose($fh);
}

?>

The HTML file that used to show the SWF chart is listed below.

<html>
<head>

<script type="text/javascript" src="js/swfobject.js"></script>
<script type="text/javascript">

swfobject.embedSWF(
"open-flash-chart.swf", "my_price_chart",
"1000", "400", "9.0.0", "expressInstall.swf",
{"data-file":"LIWA_price.json"} );

</script>

</head>
<body>

<h1>Hello world!</h1>
<div id="my_price_chart"></div>
<br>
<div id="my_volume_chart"></div>
</body>
</html>

For details to use OFC2 and the above codes, please go to OFC2 website and read more details.

Weekly Chart from StockCharts
StockCharts provides nice stock charts with some useful information. A strategy similar to get charts from Yahoo site can be adopted. The link to point to stock chart looks like http://stockcharts.com/c-sc/sc?s=ARST&p=W&b=5&g=0&i=t05444095590&r=6408. There is a problem when you directly embed the link to your website. It suggests you visit their site to view the chart instead of just show it. To solve the problem, we can download the stock charts locally and save them to PNG files. Then the charts can be used as local images. To do that, we can use Linux wget command.

wget “http://stockcharts.com/c-sc/sc?s=ARST&p=W&b=5&g=0&i=t05444095590&r=6408” -O arst.png

Share

Tags: , , , , ,

Gene network visualization

Cytoscape is an open source bioinformatics software platform for visualizing molecular interaction networks and biological pathways and integrating these networks with annotations, gene expression profiles and other state data. The following is a snapshot of the sowtware interface.

cytoscape

The current version of the software is v2.6.3. The core features of Cytoscape include data integration, visualization, and analysis. There are a lot of third party developed plugins freely available, too. Plugins are categorized in several groups: analysis, network and attribute I/O, network inference, functional enrichment, communication/scripting and others. If you have ideas to produce plugins for Cytoscape, Cytoscape provides plugin APIs for this purpose.

Share

Tags: , ,

eDigitizer user guide

As a researcher, you may encounter the following situations from time to time. You need to get original data for a graph published in a scientific paper. The simple way is to use a ruler and estimate the value of each data point by eye. If you want to get the data more accurately, you have to turn to digitization software. Back to 2002, I wrote a MATLAB program that can do the job. Unfortunately, you have to own a copy of MATLAB to use the program. As inquiries increase recently, the eDigitizer is implemented in the .NET environment. There is no MATLAB required. Now the brand new implementation can run under Windows with .Net framework version 2 installed. In addition. The following lists it main features.

  1. Zoom and rotate images
  2. Test the orthogonality of axes
  3. Digitize axes
  4. Digitize data points
  5. Save digitized data to a text file

Get eDigitizer

Visit http://www.sunfinedata.com/graphing/edigitizer/ to download a copy of the application. This is a green software. You do not need to install it. Just expand the downloaded zip file to a folder and click the executable file – edigitizer-net2.exe. Since it need Microsoft .NET framework 2.0 runtime library, you have to install .Net framework 2.0 runtime redistribution package from the Microsoft web site.

Launch eDigitizer

First launch eDigitizer by double clicking it. You have to find the program in your hard disk by using Windows explorer or similar applications. Figure 1 shows the main window of the eDigitizer.

edigitizer-main
Figure 1

There are two functional area in eDigitizer’s main window. On the left side is a fixed area that houses all function commands. First functional block is related to image processing, such as load, zoom, rotate, restore and save image. The second functional block is related to digitizing X and Y axes and testing perpendicularity of them. The last functional block includes functions to digitize series. You can digitize as many series as you want. All data will be stored in text file. On the right side includes a zooming area with multiple tabs, image tab, graph tab and data tab. It takes the major portion of the main window. The size of this area changes with the eDigitizer window. If you move the mouse cursor to this area, the cursor changes to a big blue cross. That can help users to locate points on the screen. Before you load any image to the system, these tab areas have nothing. Next step is loading image.

Load image

Loading an image is pretty simple. Just click “Browse” button on the top of left panel and an “Open an image” dialog window will pop up (Figure 2). You can navigate to the folder where images are stored and select one to open.

edigitizer-browse
Figure 2

Once the selected image is loaded, the main window looks like Figure 3.

edigitizer-image
Figure 3

Digitize axes and test perpendicularity

Now you can directly click “Test” button in the Axes frame to test the orthogonality of the axes. Move the mouse cursor to the graph and it changes to the big blue cross. You have to sample three points (the origin, one point on X axis and one point on Y axis in sequence, Figure 4) in the coordinates.

edigitizer-axes
Figure 4

Click the origin, one point on X axis and one point on Y Axis sequentially, and then you will see the Theta (θ) and Alpha (α) values in the Axes frame of the left panel (refer to Figure 3). Figure 5 shows the definition of the two angles. If the alpha value is less than 1 degree and theta is around 90 degree. The orthogonality of the axes is good. You can directly digitize data points without rotation of the image. Otherwise, you have to rotate the image based on the alpha value you got in this step.

edigitizer-test
Figure 5

Next step is digitizing X and Y axes. Click X or Y button in Axes frame. The two textboxes below the buttons will change to “Name/Unit” and “Values”. What you need to do is enter the variable name and unit of X or Y axes in the first textbox and enter a comma separate values based on you actual situation into the second textbox. For the sample image we see in Figure 3, we have the following:

X axis: Name/Unit: Time (Hour); Values: -12, 0, 12, 24, 36, 48, 60, 72
Y axis: Name/Unit: mRNA; Values: 0, 0.5, 1.0

After you enter the pair for X axis, you should click “Collect” button to digitize the points in X axis. You have to digitize the points in the same order as you enter them in the Values textbox. The application will know when you finish the digitization based on the number of values you entered in the Values textbox. Once all points are digitized, there will be linear equation with R2 value shown up just above the “Collect” button. For this situation, the intercept of the linear equation is -21.55 and the slope is 0.24 with a R2 of 1.0 (See Figure 6)

edigitizer-axes
Figure 6

You can follow the same step to digitize the three points on Y axis.

Digitize series

Now we are ready to digitize our first series. Let’s pick “wt(col)” line to demonstrate the process.

  1. Enter “wt(col)” in the Name textbox in the Series frame
  2. Click “Collect” button
  3. Move cursor to image and it will change to a big blue cross
  4. Move the big blue cross to the center of the first open square on the left of the image and click it
  5. Move the big blue cross to the next open square and click it, repeat this step until you complete the last open square on the right side of the image
  6. Click “Commit” button in the Series frame. Note: before digitizing, this button is called “Collect”.
  7. Switch to “Graph” tab, you can see the digitized series like Figure 7
  8. Switch to “Data” tab, you can see the digitized data like Figure 8

edigitizer-graph
Figure 7

edigitizer-data
Figure 8

Congratulations! You have completed your first digitization. You can click “Save” button in the Series frame to save your results to a file for late use. Is it simple? Yes, it is pretty simple. You can digitize as many series of you want and save them into one text file.

Reference

Share

Tags: , , , , ,

Frequency histogram 制作频率分布图

相关函数介绍
1.FREQUENCY函数
返回指定数据和分组的频率数组。函数FREQUENCY的语法形式为:

FREQUENCY(data_array,bins_array)

其中Data_array为一数组或对一组数值的引用,用来计算频率。如果 data_array 中不包含任何数值,函数FREQUENCY返回零数组。Bins_array为一数组或对数组区域的引用,设定对data_array进行频率计算的分段点。如果bins_array中不包含任何数值,函数FREQUENCY返回data_array元素的数目。
看起来FREQUENCY的用法蛮复杂的,但其用处很大。比如可以计算不同工资段的人员分布,公司员工的年龄分布,学生成绩的分布,不同品种的产量分布情况等。这里以具体示例说明其基本的用法。
2.NORMDIST函数
返回给定平均值和标准偏差的正态分布的累积函数。函数的语法为:

NORMDIST(x,mean,standard_dev,cumulative)

x是需要计算累计概率的数据,mean为平均值,standard_dev为标准差,cumulative可以使TRUE或FALSE,当计算累计概率时取TRUE。

应用实例
例1、计算员工年龄分布情况
1)在工作表里第一列(A2:A9)输入员工的年龄,数据为28、25、31、21、44、33、22和35;
2)在C2:C5单元格中输入25、30、35、和40;
3)选择D2:D6单元格,输入=FREQUENCY(a2:a9,c2:c5),按CTRL+SHIFT+ENTER输入数组。

这样就可以计算出年龄在25岁以下、26~30岁、31~35岁、36~40岁和40岁以上各区间中的数目。本例中选择了5个垂直相邻的单元格后,即以数组方式输入公式。返回的数组中的元素个数比bins_array(数组中的元素个数多1。第五个数字1表示大于最高间隔(40)的数值(44)的个数。函数FREQUENCY忽略空白单元格和文本值。该例在age工作表中。

例2、在处理科学试验结果时,我们往往希望看看试验数据是否符合正态分布,最简单的办法是做频率分布图。本例中生成100个随机数字,然后对这些数据做频率分布图。
1)EXCEL提供了一个数据分析包(Analysis toolpak),打开该分析包的方法是使用ADD-INS菜单命令。
2)使用菜单命令Tools|Data Analysis…,在弹出菜单中选中”Random Number Generation”,完成对话框中的相应输入框,在A2:A101单元格中生成100个随机数字。
3)命名A2:A101为data;
4)计算数据的平均值和标准差,在D1和D2中分别输入=AVERAGE(data)和=STDEV(data);
5)在C5:C17中输入8.50到11.50,以0.50为间隔,这就是Bins_array;
6)选择D5:D17,输入=frequency(data,c5:c17)并按CTRL+SHIFT+ENTER输入该公式;
7)计算总频率数,在D18中输入=sum(d5:d17);
8)计算期望频率,在E5中输入=$d$18*normdist(c5,mean,stdev,true),在E6中输入=$d$18*(normdist(c6,mean,stdev,true)-normdist(c5-mean,stdev,true)),使用向下填充直到E16,在E17中输入=$d$18*(1-normdist(c16,mean,stdev,true));
在E5中计算数据小于等于8.5的累计概率,在E6-E16中两个连续数据(一组)的期望频率,在E17中计算数据大与等于11.5的累计概率;
9)计算期望频率的总和,在D18中输入=sum(e5:e17).
10)制作频率分布图:选中D5:E17,做一个连线图(Line),单击’Series’标签,在’Category(X) axis labels’中选中C5:C17,等图形完成后,选中实际数据线,单击鼠标右键,在弹出的右键菜单中选中’Chart type’,将其设置成柱状图(Cloumn),并设置间隙为0;并格式化Normal数据为平滑曲线。

Share

Tags: , , ,