@@ -263,18 +263,25 @@ define([
263263 code . appendLine ( "import warnings" ) ;
264264 code . appendLine ( "with warnings.catch_warnings():" ) ;
265265 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 ) ) {
270277 code . appendFormatLine ( " sns.countplot(x={0})" , allocateTo ) ;
278+ } else {
279+ code . appendFormatLine ( " sns.histplot({0}, stat='density', kde=True)" , allocateTo ) ;
271280 }
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()" ) ;
274284 }
275- code . appendFormatLine ( " plt.title('Generate random numbers: {0}')" , label . replace ( "'" , "\\'" ) ) ;
276- code . appendLine ( " plt.xlabel('$x$')" ) ;
277- code . append ( " plt.show()" ) ;
278285 }
279286 break ;
280287 case 'distribution-plot' :
@@ -311,13 +318,39 @@ define([
311318 code . appendFormatLine ( " sns.countplot(x=[ x[i] for x in {0} ])" , allocateTo ) ;
312319 code . appendLine ( "plt.suptitle('Probability mass function: Multinomial')" ) ;
313320 code . appendLine ( "plt.tight_layout()" ) ;
314- code . appendLine ( "plt.show()" ) ;
321+ code . append ( "plt.show()" ) ;
315322 }
316323 }
317324 } 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+
318351 if ( probDensityFunc === true || cumDistFunc === true ) {
319352 code . appendLine ( ) ;
320- code . append ( "x = np.linspace(-5, 5 , 100)" ) ;
353+ code . appendFormat ( "x = np.linspace({0}, {1} , 100)" , start , end ) ;
321354 if ( probDensityFunc === true ) {
322355 this . addCheckModules ( 'np' ) ;
323356 this . addCheckModules ( 'plt' ) ;
@@ -340,7 +373,7 @@ define([
340373 code . appendFormatLine ( "# Cumulative distribution function ({0})" , label ) ;
341374 code . appendLine ( "import warnings" ) ;
342375 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 ) ;
344377 code . appendLine ( " plt.plot(_x, _rv.cdf(_x))" ) ;
345378 code . appendLine ( ) ;
346379 code . appendFormatLine ( " plt.title('Cumulative distribution function: {0}')" , label . replace ( "'" , "\\'" ) ) ;
0 commit comments