projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Parameter estimate matched with appropriate variable during estimation
[pspp]
/
src
/
plot-hist.c
diff --git
a/src/plot-hist.c
b/src/plot-hist.c
index 7208d3fa1257a5a2b2272737bc02bf103155789d..fd1a88d8a69cfbb325723522707eaf8471ff565c 100644
(file)
--- a/
src/plot-hist.c
+++ b/
src/plot-hist.c
@@
-14,8
+14,11
@@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA. */
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA. */
+
+/* If you add/modify any public symbols in this file, don't forget to
+ change the stubs in dummy-chart.c */
#include <config.h>
#include <config.h>
@@
-25,17
+28,21
@@
#include <gsl/gsl_histogram.h>
#include <gsl/gsl_randist.h>
#include <assert.h>
#include <gsl/gsl_histogram.h>
#include <gsl/gsl_randist.h>
#include <assert.h>
-
#include "hash.h"
#include "hash.h"
-
#include "var.h"
#include "chart.h"
#include "var.h"
#include "chart.h"
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
/* Write the legend of the chart */
void
histogram_write_legend(struct chart *ch, const struct normal_curve *norm)
{
char buf[100];
/* Write the legend of the chart */
void
histogram_write_legend(struct chart *ch, const struct normal_curve *norm)
{
char buf[100];
+ if ( !ch )
+ return ;
+
pl_savestate_r(ch->lp);
sprintf(buf,"N = %.2f",norm->N);
pl_savestate_r(ch->lp);
sprintf(buf,"N = %.2f",norm->N);
@@
-59,41
+66,46
@@
static void hist_draw_bar(struct chart *ch, const gsl_histogram *hist, int bar);
static void
hist_draw_bar(struct chart *ch, const gsl_histogram *hist, int bar)
{
static void
hist_draw_bar(struct chart *ch, const gsl_histogram *hist, int bar)
{
- double upper;
- double lower;
- double height;
+ if ( !ch )
+ return ;
- const size_t bins = gsl_histogram_bins(hist);
- const double x_pos = (ch->data_right - ch->data_left) * bar / (double) bins ;
- const double width = (ch->data_right - ch->data_left) / (double) bins ;
+ {
+ double upper;
+ double lower;
+ double height;
- assert ( 0 == gsl_histogram_get_range(hist, bar, &lower, &upper));
+ const size_t bins = gsl_histogram_bins(hist);
+ const double x_pos = (ch->data_right - ch->data_left) * bar / (double) bins ;
+ const double width = (ch->data_right - ch->data_left) / (double) bins ;
- assert( upper >= lower);
- height = gsl_histogram_get(hist, bar) *
- (ch->data_top - ch->data_bottom) / gsl_histogram_max_val(hist);
+ assert ( 0 == gsl_histogram_get_range(hist, bar, &lower, &upper));
- pl_savestate_r(ch->lp);
- pl_move_r(ch->lp,ch->data_left, ch->data_bottom);
- pl_fillcolorname_r(ch->lp, ch->fill_colour);
- pl_filltype_r(ch->lp,1);
+ assert( upper >= lower);
+ height = gsl_histogram_get(hist, bar) *
+ (ch->data_top - ch->data_bottom) / gsl_histogram_max_val(hist);
- pl_fboxrel_r(ch->lp,
- x_pos, 0,
- x_pos + width, height);
+ pl_savestate_r(ch->lp);
+ pl_move_r(ch->lp,ch->data_left, ch->data_bottom);
+ pl_fillcolorname_r(ch->lp, ch->fill_colour);
+ pl_filltype_r(ch->lp,1);
- pl_restorestate_r(ch->lp);
- {
- char buf[5];
- snprintf(buf,5,"%g",(upper + lower) / 2.0);
- draw_tick(ch, TICK_ABSCISSA,
- x_pos + width / 2.0, buf);
- }
+ pl_fboxrel_r(ch->lp,
+ x_pos, 0,
+ x_pos + width, height);
+ pl_restorestate_r(ch->lp);
+
+ {
+ char buf[5];
+ snprintf(buf,5,"%g",(upper + lower) / 2.0);
+ draw_tick(ch, TICK_ABSCISSA,
+ x_pos + width / 2.0, buf);
+ }
+ }
}
}
@@
-107,22
+119,30
@@
histogram_plot(const gsl_histogram *hist,
int i;
int bins;
int i;
int bins;
- struct chart ch;
+ struct chart
*
ch;
- bins = gsl_histogram_bins(hist);
+ ch = chart_create();
+ chart_write_title(ch, _("HISTOGRAM"));
- chart_
initialise(&ch
);
- chart_write_
title(&ch, _("HISTOGRAM")
);
+ chart_
write_ylabel(ch, _("Frequency")
);
+ chart_write_
xlabel(ch, factorname
);
- chart_write_ylabel(&ch, _("Frequency"));
- chart_write_xlabel(&ch, factorname);
+ if ( ! hist ) /* If this happens, probably all values are SYSMIS */
+ {
+ chart_submit(ch);
+ return ;
+ }
+ else
+ {
+ bins = gsl_histogram_bins(hist);
+ }
- chart_write_yscale(
&
ch, 0, gsl_histogram_max_val(hist), 5);
+ chart_write_yscale(ch, 0, gsl_histogram_max_val(hist), 5);
for ( i = 0 ; i < bins ; ++i )
for ( i = 0 ; i < bins ; ++i )
- hist_draw_bar(
&
ch, hist, i);
+ hist_draw_bar(ch, hist, i);
- histogram_write_legend(
&
ch, norm);
+ histogram_write_legend(ch, norm);
if ( show_normal )
{
if ( show_normal )
{
@@
-139,25
+159,25
@@
histogram_plot(const gsl_histogram *hist,
gsl_histogram_get_range(hist, bins - 1, ¬_used, &x_max);
assert(range == x_max - not_used);
gsl_histogram_get_range(hist, bins - 1, ¬_used, &x_max);
assert(range == x_max - not_used);
- abscissa_scale = (ch
.data_right - ch.
data_left) / (x_max - x_min);
- ordinate_scale = (ch
.data_top - ch.
data_bottom) /
+ abscissa_scale = (ch
->data_right - ch->
data_left) / (x_max - x_min);
+ ordinate_scale = (ch
->data_top - ch->
data_bottom) /
gsl_histogram_max_val(hist) ;
gsl_histogram_max_val(hist) ;
- pl_move_r(ch
.lp, ch.data_left, ch.
data_bottom);
- for( d = ch
.
data_left;
- d <= ch
.
data_right ;
- d += (ch
.data_right - ch.
data_left) / 100.0)
+ pl_move_r(ch
->lp, ch->data_left, ch->
data_bottom);
+ for( d = ch
->
data_left;
+ d <= ch
->
data_right ;
+ d += (ch
->data_right - ch->
data_left) / 100.0)
{
{
- const double x = (d - ch
.
data_left) / abscissa_scale + x_min ;
+ const double x = (d - ch
->
data_left) / abscissa_scale + x_min ;
const double y = norm->N * range *
gsl_ran_gaussian_pdf(x - norm->mean, norm->stddev);
const double y = norm->N * range *
gsl_ran_gaussian_pdf(x - norm->mean, norm->stddev);
- pl_fcont_r(ch
.lp, d, ch.
data_bottom + y * ordinate_scale);
+ pl_fcont_r(ch
->lp, d, ch->
data_bottom + y * ordinate_scale);
}
}
- pl_endpath_r(ch
.
lp);
+ pl_endpath_r(ch
->
lp);
}
}
- chart_
finalise(&
ch);
+ chart_
submit(
ch);
}
}