ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 10 Apr 2022 20:53:04 +0200Evaluate variable in plot labelhttps://ask.sagemath.org/question/61903/evaluate-variable-in-plot-label/I have several plots with labels that I would like to evaluate. For instance
all=[plot(x^(1/(i+1)),(x,0,4), rgbcolor=hue(i/10),axes_labels=[r"$x$",r"$x^{1/(1+%d)}$"%i]) for i in range(4)]
leads to `all[2]` showing me (sorry for not being able to upload due to <60 points) the plot lablel $x^{1/(1+1)}$, which
I would like to display after evaluation ($x^{1/2}$)
By defining the function $f(i)=i+1$ in the preamble of the graph I still cannot evaluate $f$, for $i$ is not evaluated inside the list
Even supposing I would, suppose I want the exponent in digits form. I am unable to find the string splicing character which also evaluates and then displays 0.5 (instead of a single digit). Does anybody know about how to correct this syntax?
c.p.Sun, 10 Apr 2022 20:53:04 +0200https://ask.sagemath.org/question/61903/How to label layouts in interact?https://ask.sagemath.org/question/59217/how-to-label-layouts-in-interact/I have a function where input is two spheres. I want to label or title the left layout as FirstSphere and right layout as SecondSphere so people know which is which.
Here is what I have now -
@interact(layout=dict(left=[['rOne'],['firstTheta'],['firstPhi]],right=[['rTwo','secondTheta','secondPhi']]))jaqatraFri, 01 Oct 2021 19:17:04 +0200https://ask.sagemath.org/question/59217/Constructing words or strings using iterationhttps://ask.sagemath.org/question/56383/constructing-words-or-strings-using-iteration/It is not allowed to label simplices with numbers or lists, and I want to enter a few thousand simplices. I am therefore trying to do something that naively looks like this:
sage: from sage.homology.simplicial_set import AbstractSimplex, SimplicialSet
sage: for i in range(4):
....: Word(('v', i)) = AbstractSimplex(0)
I have also tried using strings. Does anyone know how to do this?IngridFri, 26 Mar 2021 09:42:43 +0100https://ask.sagemath.org/question/56383/How show vector or matrix in legend label of plot in latex?https://ask.sagemath.org/question/55304/how-show-vector-or-matrix-in-legend-label-of-plot-in-latex/We can insert latex in legend labels by surrounding the text with '$'. But it doesn't work for a vector (matrix, array), e.g.
\left[\begin{array}{r} 1 \\ 0 \end{array}\right]
Is there any way to display vector in latex in legend label?robSat, 16 Jan 2021 14:32:42 +0100https://ask.sagemath.org/question/55304/edge label in graph doesn't printhttps://ask.sagemath.org/question/54722/edge-label-in-graph-doesnt-print/ I'm creating triplets from a string to avoid typing all those {}, to create a graph. Although the vertexes label properly, each third element should label an edge, but nothing happens. Otherwise it works. What is missing? Thanks.![image description](/upfiles/16081852304812413.png)
grafadds = []
triplet = "alpha beta ab beta cappa bc cappa delta cd delta gamma dg alpha beta ab gamma alpha ga gamma beta gb beta alpha ba gamma gamma gg".split()
triplet = iter(triplet)
while True:
try:
grafadds.append((next(triplet), next(triplet),next(triplet)))
except StopIteration:
break
G = Graph(multiedges=True,loops=True)
G.add_edges(grafadds)
G.show()cybervigilanteThu, 17 Dec 2020 07:08:05 +0100https://ask.sagemath.org/question/54722/Legend attached to curve in plot ("PlotLabels")https://ask.sagemath.org/question/46404/legend-attached-to-curve-in-plot-plotlabels/Hello,
I have a plot with several curves (say, 5) and I need to clearly mark them.
The plot should be grayscale friendly (I am giving curves different shades, but it is not enough), and line style (dotted...) already has a different meaning. I am using a legend, but it goes in a separate box and does not really help a lot.
Since the different curves never cross in a given plot, just attaching the legend label to the curve tail would be great: how can I achieve this? To be clear, I am looking for an equivalent of Mathematica PlotLabels.
The following example gives an idea of the 'most overlapping' case I can be interested in (actually an exaggeration, a real plot would stop at nexp=2.5):
f(x,n) = e^(-1/(n*x))
listexp = srange(0.5, 3+0.1, 0.5)
lenght = float(len(listexp))
xMinPlot = 0.1
p = Graphics()
for i,nexp in enumerate(listexp) :
c = 10^nexp
p += plot_semilogx(f(x,c), (x, xMinPlot, 10), hue=i/lenght)
p.show()
-----
Using [slelievre answer](https://ask.sagemath.org/question/46404/legend-attached-to-curve-in-plot-plotlabels/?answer=46411#post-id-46411) (and imitating the PlotLabels idea, putting gray lines between plot and label), I came up with this:
text_options = {...}
offsets = [0.01, 0.01, 0.01, -0.02, -0.02, 0.02]
xlabel = xMinPlot*0.85
xline = xMinPlot*0.97
for i,nexp in enumerate(listexp) :
c = 10^nexp
yline = f(xMinPlot,c)
p += line(((xline,yline),(xlabel,yline+offsets[i])), color='gray', thickness=0.5)
p += text('$c = 10^{{ {:.1f} }}$'.format(float(nexp)),
(xlabel, yline+offsets[i]), **text_options)
p.show(xmin=5*10^-2, xmax=10)
This approach requires to analyse each plot case by case and playing around to find a solution, but I am afraid there is nothing one can do to partially automate it.
Also, I am not sure that I am doing this the best way, or whether the result could look better/more professional.BaccoMon, 29 Apr 2019 20:10:15 +0200https://ask.sagemath.org/question/46404/Legend for histogramhttps://ask.sagemath.org/question/36210/legend-for-histogram/I can't make the legend for histograms work as I want it to. I can make a legend with the labels appear but the corresponding indicator doesn't show the colors just two black vertical lines.
Here's a minimial example:
d1=[randint(0,10) for i in range(20)]
d2=[randint(0,10) for i in range(20)]
h=histogram([d1,d2],label=["d1","d2"])
h.legend(True)
h
Any ideas?AckslSat, 07 Jan 2017 12:21:19 +0100https://ask.sagemath.org/question/36210/Label each pointhttps://ask.sagemath.org/question/28615/label-each-point/ Is it possible in Sage to label each point in a 2-D plot? I'd like to create something like this:
![image description](https://dl.dropboxusercontent.com/u/22824199/forums/sagemath/labeled%20points.PNG)
mellow_yellowSun, 19 Jul 2015 08:04:48 +0200https://ask.sagemath.org/question/28615/