Ask Your Question
0

Syntax to define a Layout of a Plot

asked 4 years ago

geroyx gravatar image

updated 4 years ago

Just for interest:
I have

reset()
import scipy.stats
n = 2000
p = 0.2
binom_dist = scipy.stats.binom(n,p)
bar_chart([binom_dist.pmf(x) for x in range(n)], frame=True, axes_labels=['$k$','$B(k,{},{})$'.format(n,float(p))])

How could outsource the part like
Layout = frame=True, axes_labels=['$k$','$B(k,{},{})$'.format(n,float(p))]?

And then

bar_chart([binom_dist.pmf(x) for x in range(n)], Layout)
Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 4 years ago

Juanjo gravatar image

Just put layout options in a dictionary:

reset()
import scipy.stats
n = 2000
p = 0.2
binom_dist = scipy.stats.binom(n,p)
Layout = {'frame': True, 'axes_labels': ['$k$', f'$B(k,{n},{float(p)})$']}
bar_chart([binom_dist.pmf(x) for x in range(n)], **Layout)

or, as an alternative syntax, you can replace the assigment to Layout by

Layout = dict(frame=True, axes_labels=['$k$', f'$B(k,{n},{float(p)})$'])
Preview: (hide)
link

Comments

Ah, very good! ;)

geroyx gravatar imagegeroyx ( 4 years ago )

I have to use your code in the kind
Layout = dict(frame=False, axes_labels=['$k$','$B(k,{},{})$'.format(n,float(p))]) bar_chart([binom_dist.pmf(x) for x in range(n)], **Layout)

But this way it works.

geroyx gravatar imagegeroyx ( 4 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 4 years ago

Seen: 742 times

Last updated: Apr 06 '20