1 | initial version |
Thanks for your question.
I tried to rephrase the essence of your question more concisely at ask-sage question 26637.
I am taking the opportunity here to make a few comments on the code you provided.
You declared a bunch of variables for nothing, you needed only declare r
since it's the only one that you are using as a symbolic variable.
You can even dispense with declaring variables at all, if you use x
in your function definitions (since x
is defined when you open Sage).
You are creating a lot of plots with mostly the same options, so it would be worth making a dictionary out of those, and using that dictionary each time.
This way, if you spot a typo (eg Illuminace > Illuminance), or decide to use SI units (lux > lx), and so on, you only have to make the change in one place, and you don't risk forgetting one of the occurrences.
By the way it looks like this is what happened with your ymin and ymax, which are 1e-4 to 0.3 in some places, and 0 to 0.1 in other places.
Apparently the line
doesn't work well in log scale, that would be worth a question in itself.
A workaround is to use a parametric plot.
You don't need semi-colons all over the place.
You have some ticks outside the y-range.
Putting all these remarks into use, here is how I would rewrite your code.
f1 = 1.0 / x^2 * exp(-x/50.)
f2 = 2.4 / x^2 * exp(-x/50.)
f3 = 4.0 / x^2 * exp(-x/50.)
f4 = 5.0 / x^2 * exp(-x/50.)
f5 = 15.0 / x^2 * exp(-x/50.)
x_range = (x,13,200)
gen_options = {
'ymin': 1e-4,
'ymax': 3e-1,
'scale': ('loglog', 10),
'axes': False,
'frame': True,
'ticks': ([13, 1e2, 200],
[1e-4, 1e-3, 1e-2, 1e-1]),
'axes_labels': ('Distance between led and camera [m]',
'Illuminance on camera sensor [lx]'),
}
title_options = {
'title': 'L_s (scattering length) = 50 m',
}
def lplot(f, title=False, **options):
loc_options = gen_options.copy()
loc_options.update(options)
if title: loc_options.update(title_options)
return plot(f, x_range, **loc_options)
z = Graphics()
z.set_legend_options(loc=1)
Lg1 = lplot(f1, color='blue', legend_label='I = 1.0 cd', title=True)
Lg2 = lplot(f2, color='black', legend_label='I = 2.4 cd')
Lg3 = lplot(f3, color='red', legend_label='I = 4.0 cd')
Lg4 = lplot(f4, color='green', legend_label='I = 5.0 cd')
Lg5 = lplot(f5, color='violet', legend_label='I = 15. cd')
cp3 = lplot(2e-1, linestyle='dashed', color='red')
cp4 = lplot(1e-6, linestyle='dashed', color='gray')
cp5 = lplot(5e-4, linestyle='dashed', color='gray')
cp6 = lplot(8e-5, linestyle='dashed', color='gray')
# g = line(((20,0), (20, 0.1)), color='black') # seems broken in log scale
# workaround for `line` in log scale: use parametric_plot
# (setting aspect_ratio to auto -- it defaults to 1 in parametric_plot)
g = parametric_plot((20,x), (x,0,0.1), color='black',
aspect_ratio='automatic', **gen_options)
z += g + Lg1 + Lg2 + Lg3 + Lg4 + Lg5 + cp3 + cp4 + cp5 + cp6
z