@@ -263,18 +263,25 @@ define([
263
263
code . appendLine ( "import warnings" ) ;
264
264
code . appendLine ( "with warnings.catch_warnings():" ) ;
265
265
code . appendLine ( " warnings.simplefilter(action='ignore', category=Warning)" ) ;
266
- if ( this . distList [ 0 ] . child . includes ( distType ) ) {
267
- if ( distType === 'multinomial' ) {
268
- code . appendFormatLine ( " plt.boxplot(x={0})" , allocateTo ) ;
269
- } else {
266
+ if ( distType === 'multinomial' ) {
267
+ // code.appendFormatLine(" plt.boxplot(x={0})", allocateTo);
268
+ code . appendFormatLine ( " for i in range(0, {0}.shape[1]):" , allocateTo ) ;
269
+ code . appendLine ( " plt.subplot(2, 2, i+1)" ) ;
270
+ code . appendLine ( " plt.title('$x$=' + str(i))" ) ;
271
+ code . appendFormatLine ( " sns.countplot(x=[ x[i] for x in {0} ])" , allocateTo ) ;
272
+ code . appendLine ( " plt.suptitle('Generate random numbers: Multinomial')" ) ;
273
+ code . appendLine ( " plt.tight_layout()" ) ;
274
+ code . appendLine ( " plt.show()" ) ;
275
+ } else {
276
+ if ( this . distList [ 0 ] . child . includes ( distType ) ) {
270
277
code . appendFormatLine ( " sns.countplot(x={0})" , allocateTo ) ;
278
+ } else {
279
+ code . appendFormatLine ( " sns.histplot({0}, stat='density', kde=True)" , allocateTo ) ;
271
280
}
272
- } else {
273
- code . appendFormatLine ( " sns.histplot({0}, stat='density', kde=True)" , allocateTo ) ;
281
+ code . appendFormatLine ( " plt.title('Generate random numbers: {0}')" , label . replace ( "'" , "\\'" ) ) ;
282
+ code . appendLine ( " plt.xlabel('$x$')" ) ;
283
+ code . append ( " plt.show()" ) ;
274
284
}
275
- code . appendFormatLine ( " plt.title('Generate random numbers: {0}')" , label . replace ( "'" , "\\'" ) ) ;
276
- code . appendLine ( " plt.xlabel('$x$')" ) ;
277
- code . append ( " plt.show()" ) ;
278
285
}
279
286
break ;
280
287
case 'distribution-plot' :
@@ -311,13 +318,39 @@ define([
311
318
code . appendFormatLine ( " sns.countplot(x=[ x[i] for x in {0} ])" , allocateTo ) ;
312
319
code . appendLine ( "plt.suptitle('Probability mass function: Multinomial')" ) ;
313
320
code . appendLine ( "plt.tight_layout()" ) ;
314
- code . appendLine ( "plt.show()" ) ;
321
+ code . append ( "plt.show()" ) ;
315
322
}
316
323
}
317
324
} else {
325
+ let start = - 5 ;
326
+ let end = 5 ;
327
+ switch ( distType ) {
328
+ case 'normal' :
329
+ case 'studentst' :
330
+ case 'multivariate_normal' :
331
+ start = - 5 ;
332
+ end = 5 ;
333
+ break ;
334
+ case 'uniform' :
335
+ case 'beta' :
336
+ case 'dirichlet' :
337
+ start = 0 ;
338
+ end = 1 ;
339
+ break ;
340
+ case 'gamma' :
341
+ case 'chi2' :
342
+ start = 0 ;
343
+ end = 30 ;
344
+ break ;
345
+ case 'f' :
346
+ start = 0 ;
347
+ end = 10 ;
348
+ break ;
349
+ }
350
+
318
351
if ( probDensityFunc === true || cumDistFunc === true ) {
319
352
code . appendLine ( ) ;
320
- code . append ( "x = np.linspace(-5, 5 , 100)" ) ;
353
+ code . appendFormat ( "x = np.linspace({0}, {1} , 100)" , start , end ) ;
321
354
if ( probDensityFunc === true ) {
322
355
this . addCheckModules ( 'np' ) ;
323
356
this . addCheckModules ( 'plt' ) ;
@@ -340,7 +373,7 @@ define([
340
373
code . appendFormatLine ( "# Cumulative distribution function ({0})" , label ) ;
341
374
code . appendLine ( "import warnings" ) ;
342
375
code . appendLine ( "with warnings.catch_warnings():" ) ;
343
- code . appendLine ( " _x = np.linspace(-5, 5 , 100)" ) ;
376
+ code . appendFormatLine ( " _x = np.linspace({0}, {1} , 100)" , start , end ) ;
344
377
code . appendLine ( " plt.plot(_x, _rv.cdf(_x))" ) ;
345
378
code . appendLine ( ) ;
346
379
code . appendFormatLine ( " plt.title('Cumulative distribution function: {0}')" , label . replace ( "'" , "\\'" ) ) ;
0 commit comments