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.Mon, 01 Jul 2024 01:31:31 +0200vertex labels exceed space and intersect with edgeshttps://ask.sagemath.org/question/78072/vertex-labels-exceed-space-and-intersect-with-edges/The following code generates a supersingular isogeny graph. However the problem is, that the white circle that represents the vertices of the graph (generated by the parameter 'talk') is not big enough to contain the entire label of the vertex. The labels exceeds the space left for it and I did not find any way to fix this
Can anyone tell me how to produce a graph that looks something like [this](https://eprint.iacr.org/2019/1321.pdf)(page 10, fig 4), where the vertex size is adapted to the length of the vertex label?
If I set 'talk=False' then the vertex is representend by a small dot, but then again the label is sometimes only partially readable, is intersecting with the edges and sometimes even with other vertex labels.
However, it would also be helpful if I could give the vertex labels some off-set, for example 2cm to the right of the vertex or something like this.
I considered all Plot opstions on the doc page and did not find any solution for my problem. However, maybe there is some kind of work around. Unfortunately I do not have enough experience with sage myself so any help on this would be very helpful.
def explore(G, E, done,degree):
jE = E.j_invariant()
G.add_vertex(jE)
done.append(jE)
for i in E.isogenies_prime_degree(degree):
F = i.codomain()
jF = F.j_invariant()
if jF not in done:
explore(G, F,done,degree)
if jE != jF:
G.add_edge(jE, jF)
return G
k.<i> = GF(431^2, modulus=x^2+1)
degree = 2
E = EllipticCurve(k,[1,0])
done=[]
G=explore(Graph(), E, done,degree)
Gr=G.plot(layout='spring', vertex_labels =True, vertex_color= 'black', talk=True, figsize=15)
I would highly appreciate any help on this!WizzelgartenMon, 01 Jul 2024 01:31:31 +0200https://ask.sagemath.org/question/78072/plot circle using complex numbershttps://ask.sagemath.org/question/78022/plot-circle-using-complex-numbers/ I want to plot the $z\in\mathbb{C}$ such that $|z-a|=2$ using the CDF function.
What I have tried is
a = CDF(3,0)
C1 = solve(CDF(z-a).abs()==2,z)
But I cannot use a symbolic expression.
My idea is to plot the points given in C. I would really appreciate any answer solving the problem using the ComplexDoubleField.KingUncrownedThu, 27 Jun 2024 23:34:13 +0200https://ask.sagemath.org/question/78022/Not interactive plothttps://ask.sagemath.org/question/77963/not-interactive-plot/ I'm using method="js" in plotting. However I do not want to have an interactive plot.
For instance, if you try
HH= Graph('Oq@?oOOB?ACOGW_A?`_@a', format='graph6')
HH.show(method="js",vertex_labels=True)
you will get an interactive plot.bobby.mirSun, 23 Jun 2024 04:38:42 +0200https://ask.sagemath.org/question/77963/Incorrect plothttps://ask.sagemath.org/question/77429/incorrect-plot/ I am trying to plot the following:-
show(plot(pow(x,3) - 2*pow(x, 2) - 5 * x + 6, -200, 200))
I am expecting a wavy line intersecting the x axis at -2, 1, and 3, but I am getting a graph which looks like pow(x, 3). I am not sure why it is ignoring the rest of the equation. I can plot this graph in GraphToy.
I would share pictures and links, but my karma is too low, so go to graphtoy .com and copy the following text:-
pow(x,3)-2*pow(x,2)-5*x+6
Into the first function to see what I mean.KamBhaWed, 15 May 2024 04:38:41 +0200https://ask.sagemath.org/question/77429/Combine sage plot with matplotlibhttps://ask.sagemath.org/question/76260/combine-sage-plot-with-matplotlib/I would like to combine the plots (canvases) of Sage and Matplotlib in one plot. The following is an example script. As you can see (if you run), that Sage is just putting another image on top of the canvas of Matplotlib... Any way to just update the canvas of matplotlib to combine two plots in one plot?
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
x = [1, 2, 3, 4, 5]
y = [1, 2, 3, 4, 5]
ax.plot(x, y)
c = circle((1,1),1)
c_matplotlib = c.matplotlib(figure=fig)
plt.show()
Rowing0914Tue, 27 Feb 2024 14:07:46 +0100https://ask.sagemath.org/question/76260/Exporting pgf plots for latex from Sage environment using pandas and matplotlibhttps://ask.sagemath.org/question/76172/exporting-pgf-plots-for-latex-from-sage-environment-using-pandas-and-matplotlib/I've done some data analysis using Pandas in Sage, and would like to export plots to include in a paper. Unfortunately, exporting as a pdf means that titles etc. won't adjust to changes in the formatting of my Latex document, so I would like to export as a pgf (as explained, for example, [here](https://jwalton.info/Matplotlib-latex-PGF/)).
When I do this, however, I get the following error:
File ~/sage/sage/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/matplotlib/backends/backend_pgf.py:293, in LatexManager.__init__(self)
290 self._setup_latex_process(expect_reply=False)
291 except FileNotFoundError as err:
292 raise RuntimeError(
--> 293 f"{self.latex.args[0]!r} not found. Install it or change "
294 f"rcParams['pgf.texsystem'] to an available TeX "
295 f"implementation.") from err
296 except OSError as err:
297 raise RuntimeError(
298 f"Error starting process {self.latex.args[0]!r}") from err
AttributeError: 'LatexManager' object has no attribute 'latex'
It seems that somehow matplotlib is not able to find the correct latex implementation, but I'm not sure how to fix that. Does anyone do this regularly and know of a solution? If it's relevant, I am running Sage 10.0.beta6 on WSL. I also have a MWE below for reference. Thanks so much!
MWE:
sage: import matplotlib
sage: import matplotlib.pyplot as plt
sage: matplotlib.use('pgf')
sage: import pandas as pd
sage: df = pd.DataFrame({'length' : [float(x) for x in [1.5,0.5,1.2,0.9,3]],
....: 'width' : [float(x) for x in [0.7, 0.2, 0.15, 0.2, 1.1]]}, index = ['
....: pig', 'rabbit', 'duck', 'chicken', 'horse'])
sage: hist = df.hist(bins = 3)
sage: plt.savefig("test.pgf")
stillconfusedThu, 22 Feb 2024 19:08:10 +0100https://ask.sagemath.org/question/76172/Is there a plot function for ordered trees?https://ask.sagemath.org/question/76130/is-there-a-plot-function-for-ordered-trees/My workflow is:
# Integer compositions -> Dyck paths
def dyckpath(c):
return DyckWord(sum([[1]*a + [0]*a for a in c], []))
You can print a dyckpath with
dyck = dyckpath(c)
dyck.pretty_print(type="NE-SE")
But my question is related to:
for c in Compositions(5):
dyck = dyckpath(c)
bit = dyck.to_binary_tree()
print(bit.as_ordered_tree())
This gives me something which looks like
[[[[], []], []], [[[], []], [[[], []], []]]]
Is there a plot function that knows this format
and transforms it into a nice plot?
Edit: Taking John's answer as a starting point I tried:
ot = bit.as_ordered_tree()
show(ot.plot())
This works, but note that you have to use additionally
the function 'show'.
According to this logic I would now expect that show(bit.plot())
would also work. Unfortunately, this is not the case. Then you get
the error message: 'BinaryTrees_all_with_category.element_class'
object has no attribute 'plot'. What can I do in this case?Peter LuschnyTue, 20 Feb 2024 22:14:03 +0100https://ask.sagemath.org/question/76130/Plot spines show in middle of graphhttps://ask.sagemath.org/question/72484/plot-spines-show-in-middle-of-graph/Hi. I am new to SageMath. I like what I see, thanks!
I ran into a tiny but annoying problem: I draw a `region_plot` and it works very well, but the spines of the plot are drawn down the middle. I tried to make them go away using the standard `matplotlib` capabilities but they will not disappear. Here is my code:
reset()
a,b,c,x,y = var('a b c x y')
from matplotlib import spines, axes
i = 16
p = region_plot(
tan(x^2 - y^2)>0,
(-i*pi,+i*pi), (-i*pi,+i*pi),
incol='green',outcol='lightblue',
)
p.matplotlib().axes[0].spines[['left', 'bottom']].set_position('zero')
p.matplotlib().axes[0].spines[['top', 'right']].set_visible(False)
p
I am using SageMath on
- Ubuntu 22.04 installed in WSL
- Notebook is VSCode notebook with vscode-Jupyter extension
- Vscode version 1.80
The entire above code is run in a single cell
ThanksGPNSat, 12 Aug 2023 15:48:13 +0200https://ask.sagemath.org/question/72484/plot a function with roots highlightedhttps://ask.sagemath.org/question/74126/plot-a-function-with-roots-highlighted/Hello. I have a polynomial function. I want to plot it in a way that it's roots are highlighted, meaning when y == 0
I accept the answer even if the plot does not cover all roots and only a range of x. sage24353453453463454Tue, 31 Oct 2023 21:23:10 +0100https://ask.sagemath.org/question/74126/Ticks formatter roundinghttps://ask.sagemath.org/question/72369/ticks-formatter-rounding/Hi all,
On sage 10.0, the code
var('x,y')
f(x,y) = sqrt(x^2 + y^2)
C = contour_plot(f ,(-0.2,0.2), (-0.2,0.2), axes = True, cmap = "Spectral",
labels = True, label_fmt=lambda x: "$%s$"%round(x,2), label_colors="black",
label_inline=True,
label_fontsize=16,
gridlines=True, axes_labels=["$x$","$y$"],
ticks = [[-0.2,-0.1,0,0.1,0.2],[-0.2,-0.1,0,0.1,0.2]],
tick_formatter = "latex", fontsize= 16)
produces a figure in which the ticks markers are more like -0.200000000000, see the figure. I cannot figure out how to print a nice -0.2 (using latex) instead.
Any ideas? Thanks in advance!
![image description](/upfiles/16915988167563157.png)
JCWed, 09 Aug 2023 18:34:48 +0200https://ask.sagemath.org/question/72369/Geodesic Won't Plothttps://ask.sagemath.org/question/68694/geodesic-wont-plot/ %display latex
M = Manifold(3, 'M', structure='Lorentzian')
X.<t,x,y> = M.chart('t x y')
X
v=.5
r=sqrt((x-v*t)^2+y^2)
f=(tanh(r+4)-tanh(r-4))/(2*tanh(4))
g = M.metric()
g[0,0] = (v^2*f^2-1)
g[0,1] = -v*f
g[1,1] = 1
g[2,2] = 1
g.display()
p = M((0,0,1), name='p')
v = M.tangent_space(p)((2/3,1,0), name='v')
v.display()
s = var('s')
c = M.integrated_geodesic(g, (s, 0, 10), v, name='c')
sol = c.solve()
interp = c.interpolate()
graph = c.plot_integrated()
p_plot = p.plot(size=30, label_offset=-0.07,
fontsize=20) v_plot =
v.plot(label_offset=0.05, fontsize=20)
graph + p_plot + v_plot
This either doesn't work or takes an indeterminate amount of time to plot. However, if I change v from 0.5 to 1, it does fine. Any idea why that is?Jack ZuffanteWed, 24 May 2023 04:51:20 +0200https://ask.sagemath.org/question/68694/How to plot stream lines of an ODE with one single variable?https://ask.sagemath.org/question/68297/how-to-plot-stream-lines-of-an-ode-with-one-single-variable/I want to see the stream line plot for y' = -sin(x).
The solution of this ODE is coded as:
x = var('x')
y = function('y')(x)
de = diff(y,x) == -sin(x)
h = desolve(de,y)
solution = h.function(x)
show(solution)
I can produce the desired slope field ad hoc like this:
f(x,y)= - sin(x)
streamline_plot(f(x,y),(x,-10,10),(y,-5,5))
However, I am not able to get the right expression in the code for the stream line plot using the functions already defined above: `h`, `solution` or `y`
**What would be the more natural expression for the general (and a particular solution) plots?**toniTue, 09 May 2023 18:05:24 +0200https://ask.sagemath.org/question/68297/Problem with Geodesic Plottinghttps://ask.sagemath.org/question/68301/problem-with-geodesic-plotting/ The output of all this for me was an x-y plot with a p_0, but no curve. I'm noticing that there is a message at the bottom that maybe implies that ymax and xmax were forced to be 0. Does this have anything to do with why there is no curve visible?
%display latex
M = Manifold(3, 'M', structure='Lorentzian')
X.<t,x,y> = M.chart(r't:(-oo,+oo) x:(-oo,+oo) y:(-oo,+oo)')
X
R2 = Manifold(2, 'R^2', latex_name=r'\mathbb{R}^2')
X2.<x,y> = R2.chart()
to_R2 = M.diff_map(R2, {(X, X2): [x,y]})
to_R2.display()
r=sqrt((x-3*t)^2+y^2)
f=(tanh(r+4)-tanh(r-4))/(2*tanh(4))
g = M.metric()
g[0,0] = (9*f^2-1)
g[0,1] = -3*f
g[1,1] = 1
g[2,2] = 1
g.display()
p0 = M.point((0,0,0), name='p_0')
v0 = M.tangent_space(p0)((1.25, 5, 0), name='v_0')
v0.display()
s = var('s')
geod = M.integrated_geodesic(g, (s, 0, 5), v0); geod
sol = geod.solve()
interp = geod.interpolate()
graph = geod.plot_integrated(chart=X2, mapping=to_R2, plot_points=10,
thickness=2, label_axes=False)
graph += p0.plot(chart=X2, mapping=to_R2, size=4)
show(graph)
Integrated geodesic in the 3-dimensional Lorentzian manifold M
lsoda-- at t (=r1), too much accuracy requested
for precision of machine.. see tolsf (=r2)
in above, r1 = 0.5000000000000D-01 r2 = NaN
verbose 0 (2201: graphics.py, get_minmax_data) xmin was NaN (setting to 0)
verbose 0 (2201: graphics.py, get_minmax_data) xmax was NaN (setting to 0)
verbose 0 (2201: graphics.py, get_minmax_data) ymin was NaN (setting to 0)
verbose 0 (2201: graphics.py, get_minmax_data) ymax was NaN (setting to 0)
Launched png viewer for Graphics object consisting of 3 graphics primitivesJack ZuffanteTue, 09 May 2023 19:51:27 +0200https://ask.sagemath.org/question/68301/Changing Tick Marks on Geodesic Plothttps://ask.sagemath.org/question/67463/changing-tick-marks-on-geodesic-plot/ %display latex
M = Manifold(3, 'M', structure='Lorentzian')
X.<t,p,th> = M.chart(r't:(-oo,+oo) p:(-oo,+oo) th')
X
R2 = Manifold(2, 'R^2', latex_name=r'\mathbb{R}^2')
X2.<x,y> = R2.chart()
to_R2 = M.diff_map(R2, {(X, X2): [sqrt(5*p^2+4*t^2)*cos(th), sqrt(5*p^2+4*t^2)*sin(th)]})
to_R2.display()
g = M.metric()
g[0,0], g[1,1] = -1, 1
g[2,2] = 5*p^2+4*t^2
g.display()
p0 = M.point((-7, 10, 0), name='p_0')
v0 = M.tangent_space(p0)((1, -sqrt(120930)/348, (1)/696), name='v_0')
v0.display()
s = var('s')
geod = M.integrated_geodesic(g, (s, 0, 15), v0); geod
sol = geod.solve()
interp = geod.interpolate()
graph = geod.plot_integrated(chart=X2, mapping=to_R2, plot_points=500,
thickness=2, label_axes=True)
graph += p0.plot(chart=X2, mapping=to_R2, size=4)
show(graph)
With this code, the x-y plot has different tick mark intervals for each axis. How can I make each axis the same?
Jack ZuffanteMon, 10 Apr 2023 18:51:22 +0200https://ask.sagemath.org/question/67463/plot scattered datahttps://ask.sagemath.org/question/65806/plot-scattered-data/I'm totally new and ingnorant in sage however trying to learn by doing.
Thanks to other tips that I got here, I managed to make a real progress and now struggling with something that is pretty straightforward in other environments not in sage because of the logic (that I'm still missing)
i'm putting the full example that I simplified to focus on the issue.
i;e in practice I don't have these two functions.
One has to understand that I have no contro on the structure of the data that I need to plot. it's simply two vectors u & v in R^2
#example:
f(x) = 2*sin(2*x+4)
g(x) = 3*sin(-x-4)
eq=f-g
pf = plot(f(x), (x,-pi,pi), color="red", fill=max_symbolic(f(x),g(x)),
fillcolor="lightgreen")
pg = plot(g(x), (x,-pi,pi), color="blue")
show(pf+pg)
nbi=20
endpoints = [-pi+2*pi*i/(nbi-1) for i in range(nbi)]
c=[]
for i in range(nbi-1):
try:
a=endpoints[i]
b=endpoints[i+1]
sol=eq.find_root(a,b)
c.append(n(sol,digits=3))
except RuntimeError:
rep="no sol" #sometime I need to treat that properly
yc=[f(k) for k in c]
mypoints=[[c[k],f(c[k])] for k in range(len(c))]
print(mespoints)
# problems appear from here
ph=plot(mypoints, marker="*",color="black")
show(pf+pg+ph)
Basically I just need to approx highlight the zeros of f-g (intersection points)
any help is a step further in my learning path.
thx
MmoonSat, 07 Jan 2023 13:58:18 +0100https://ask.sagemath.org/question/65806/highlighting specific regions in a plothttps://ask.sagemath.org/question/65649/highlighting-specific-regions-in-a-plot/I'm working on displayind*g the regions where a specific condition between two functions.
As an example I want to color or highlight in a way or another the areas where let's say where x/ f(x)<g(x)
f(x)=sin(2*x + 3)
g(x)=2*cos(2*x + 2)
plot([f(x),g(x)],[x,-pi,pi])
How can I approach that ?
Thx for any kind of hint.moonSun, 01 Jan 2023 15:29:08 +0100https://ask.sagemath.org/question/65649/latex code of plotshttps://ask.sagemath.org/question/65047/latex-code-of-plots/ Dear,
I'm trying to get the LaTeX code of a given plot.
While it works fine in cocalc, I'm not able to get it done in my sageMath environment.
It looks like I'm missing some libraries.
s=plot(cos(x),[x,-pi,pi])
show(s)
print(latex(s)) #checkpoint
with open("tmp/demo.tex", 'w') as f:
f.write(str(latex(s))) #ultimate target
f.close()
Here is the error generated:
ValueError: Matplotlib requires either xelatex, lualatex, or pdflatex.
Any idea ?moonThu, 24 Nov 2022 19:57:05 +0100https://ask.sagemath.org/question/65047/Difficulty with log and ploting loghttps://ask.sagemath.org/question/64727/difficulty-with-log-and-ploting-log/x >= 0
x <= 2
g(x) = ln(x)
h(x) = (x - 2 ) ^ 2
f(x) = g(x) - h(x)
print(f)
show(plot(f))
i want to combine the funtions g(x) and h(x) but instead of giving me
ln(x) - ( x - 2)^2, it gives me log(x) - (x-2)^2 for some reason
after that, when i try to plot the funtion it is zoomed in too much(it only shows me form -1 to 1) and is also incorrect
i would like to know if there is any simple ways to fix these problemsCoolAlexTue, 01 Nov 2022 19:06:14 +0100https://ask.sagemath.org/question/64727/Decouple computing data for a plot and creating the plot object?https://ask.sagemath.org/question/64715/decouple-computing-data-for-a-plot-and-creating-the-plot-object/The `plot()` function does Two Things:
1. takes your function and samples its values (somewhat intelligently) to create a list of 2D coordinate pairs
2. uses that list of coordinates to create a plot object
Is there a way to decouple these steps, i.e. separately invoke the logic of step 1 to obtain a list of 2D points and then the logic of step 2 to obtain the plot object?
The motivation for this is computing different curves of a composite plot on different cores using `@parallel`. Very unfortunately the return value of plot(), whatever it is, doesn't pickle/unpickle properly, and thus cannot be returned between threads. So if you generate separate plot objects in your `@parallel` function, all you will get at the call point will be an iterator yielding error messages. This could be avoided if I could _just_ compute the 2D data lists in threads, and "render" them to a plot in the main thread.
Is that doable?
Please be aware that I am interested in **using** `plot()`'s **actual logic** for sampling the plotted function, rather than writing my own logic that would probably be inferior.
EDIT: toy example
@parallel
def singlePlot(v):
x = var('x')
return plot((x-v)^2, xmin=-3, xmax=3)
plots = [];
for onePlot in singlePlot([0,1,2,3]):
plots.append(onePlot)
plots[0]
Outputs:
(((0,), {}), "INVALID DATA invalid load key, 'x'.")
The same `singlePlot()` function works as expected if I remove the `@parallel` decorator and call it with a single integer rather than a list.RulatirMon, 31 Oct 2022 22:31:42 +0100https://ask.sagemath.org/question/64715/Clipping a 2D plothttps://ask.sagemath.org/question/64131/clipping-a-2d-plot/Dear all,
Best is a small example:
def fC(p):
return([p[0]/(p[0]+2), (p[1]+1)/(p[0]+2)])
def actOnD(Dom, nbsteps, myz):
DomainfC = list(map(fC, Dom))
acolor = Color(0, (20+90*nbsteps)/255, 150/255)
ToPlot = polygon(Dom, color = acolor, zorder = myz)
if nbsteps > 0:
DomainfC = list(map(fC, Dom))
ToPlot += actOnD(DomainfC, nbsteps-1, myz+1)
return(ToPlot)
actOnD( [[0,0], [0,1], [1,1], [1,0]], 3, 1)
And I would like to show only the plot within a smaller square than the unit one. It seems add_conditions works for parametric plot (though I did not find the documentatin for that, only posts).
Many thanks for your lights on that!
Best, OlivierOlivier R.Wed, 21 Sep 2022 13:56:06 +0200https://ask.sagemath.org/question/64131/Plotting a periodic functionhttps://ask.sagemath.org/question/63821/plotting-a-periodic-function/I want to plot a function that is abs(x) for -1<= x <= 1 and repeats to create a sawtooth shaped function. With the code
def h(x):
while x>1:
x=x-2
return abs(x)
h(4.3)
The Sage sell server tells me the value is 0.300000000000000, which is what I want as h(4.3)=h(2.3)=h(.3)=abs(.3) However, when I tried to plot h(x) with
def h(x):
while x>1:
x=x-2
return abs(x)
plot(h(x),x,0,5)
The plot looks like abs(x), so that h(4.3) now appears to be 4.3.
What has gone wrong? How can I properly plot the h(x) I want?
**EDIT:** A points plot gives me the output I am expecting, which is different than `plot(h(x),x,0,5)`.
def h(x):
while x>1:
x=x-2
return abs(x)
points([(x, h(x)) for x in srange(0,5,.01)], pointsize=20)dazedANDconfusedMon, 29 Aug 2022 02:54:24 +0200https://ask.sagemath.org/question/63821/How to interpolate a curve from a set of pointshttps://ask.sagemath.org/question/63082/how-to-interpolate-a-curve-from-a-set-of-points/ I have a set of points on the plane, and I want to interpolate these points to make a smooth curve.
I tried with spline() or even creating the lagrange polynomial, but the problem is that with these options I can only interpolate functions (so for example, if I have a discrete set of points of a circle, I cannot get the circle with spline() since it will interpolate the points following te x-axis order).
Is there any option to interpolate a curve following the order of points given in the list?
JBFri, 01 Jul 2022 15:30:15 +0200https://ask.sagemath.org/question/63082/I can't generate graphs."The kernel appears to have died"https://ask.sagemath.org/question/62218/i-cant-generate-graphsthe-kernel-appears-to-have-died/ I have installed Sage on my Windows 10 machine
SageMath version 9.3, Release Date: 2021-05-09
Using Python 3.7.10.
I tried to plot something simple like
plot(x^2)
I received this message in Jupyter Notebook:
Kernel Restarting.
The kernel appears to have died. It will restart automatically.
And this message SageMath 9.3 Notebook Server
Unhandled SIGSEGV: A segmentation fault occurred.
This probably occurred because a *compiled* module has a bug
in it and is not properly wrapped with sig_on(), sig_off().
Python will now terminate.
------------------------------------------------------------------------
[I 18:19:09.280 NotebookApp] KernelRestarter: restarting kernel (1/5), keep random ports
WARNING:root:kernel 7bc88a4e-b9a1-488d-bbe6-fa359a6758ab restarted
I have the same problem using matplotlib , for example:
import matplotlib.pyplot as plt
import numpy as np
t = np.linspace(0,1,10)
plt.plot(t,t**2)
plt.show()
jvg21352Sat, 30 Apr 2022 01:37:24 +0200https://ask.sagemath.org/question/62218/Evaluate 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/refresh with three.jshttps://ask.sagemath.org/question/61806/refresh-with-threejs/In some analysis/education projects I would like to compare different situations; like the Kerr GR diagrams which have lots of moving parts (sorry for the pun).
Which is to say: generate plot(s) ⇾ save as HTML (s)(or some such) ⇾ open the file(s) with a browser.
Then change plot parameters and resave and have the open pictures update automatically. Actually, I presume that the three.js would have them monitoring the HTML file as in:
[Stack overflow here:](https://stackoverflow.com/questions/5588658/auto-reload-browser-when-i-save-changes-to-html-file-in-chrome)
although a triggered update would be fine, but that answer seems simple enough to put in the three.js (template?) myself.
I realize that I could do the update manually in the browser toolbar; but being distractible and forgetful, it would be better to have it automatic. Although I am open to other suggestions.
I really enjoy moving around the parameter space as well as objects, visually oriented :); and I think sagemath does wonderful plots.rrogersSun, 03 Apr 2022 22:54:13 +0200https://ask.sagemath.org/question/61806/Plotting Zero-free regionshttps://ask.sagemath.org/question/61733/plotting-zero-free-regions/So I am working on a project for proving different types of zero-free regions, I needed to plot some zero free regions using sage and cannot think any obvious ways to do it. I am still pretty new to sage and computational math in general but I needed some guidance as to what I should do.
I am trying to plot the zero free region by de la Vall ́ee Poussin which is $1-\beta \leq \frac{c}{\log(t)}$prathamlalwaniTue, 29 Mar 2022 06:02:04 +0200https://ask.sagemath.org/question/61733/How to change the label text size of verticeshttps://ask.sagemath.org/question/61600/how-to-change-the-label-text-size-of-vertices/When I have a graph with over 1000 vertices, vertex label text is too small to read,
but it seems there is no method dealing with this issue?
I was only able to find the ticket #13827 from 6 years ago raising the same issue without a fix:
"fontsize affects to size of title font, not for vertex label or edge label font sizes."
Is there any way to change label text size?
DrewCThu, 24 Mar 2022 03:02:13 +0100https://ask.sagemath.org/question/61600/Contour Plot of 1/(2*pi*sqrt(x^2 + y^2)), why is it square? How to fix it?https://ask.sagemath.org/question/61288/contour-plot-of-12pisqrtx2-y2-why-is-it-square-how-to-fix-it/I plotted the contour plot of a function `1/(2*pi*sqrt(x^2 + y^2))`.
The code is below:
contour_plot(1/2/(pi*sqrt(x^2 + y^2)), (x, -0.1, 0.1), (y, -0.1, 0.1),
plot_points=20, colorbar=True)
**The output result is not round, but square! Why?**
**How to fix it?**Tube777tubeSat, 26 Feb 2022 15:44:14 +0100https://ask.sagemath.org/question/61288/TeX label and running list-variable simultaneously in a plot legend (or plot title)https://ask.sagemath.org/question/61112/tex-label-and-running-list-variable-simultaneously-in-a-plot-legend-or-plot-title/I want to use a `[... for n in ...]` to generate plots. How can I combine in a legend and/or title, TeX with the variable that runs (here $n$) to generate the list of plots? Minimal example:
some_plots=[plot(x^n,(x,0,1.1),title=r'$x^n$ where $n$ takes the value in the box
(format is not nice, though)',
legend_label=n, rgbcolor=hue(.1*n)) for n in range(0,10)]
sum(some_plots[s] for s in range(0,10))
which shows a box with colors, and, separately the title. How can I add $n$ to the box? If I combine TeX and the variable (like `$x^n$=n`) I get errors. (I cannot upload yet pictures, which would make the question very clear)c.p.Tue, 15 Feb 2022 16:15:27 +0100https://ask.sagemath.org/question/61112/Why specifying `stylesheet` parameter in plot function causes error?https://ask.sagemath.org/question/61081/why-specifying-stylesheet-parameter-in-plot-function-causes-error/I'm disappointed by how the default plot style looks, so I decided to find some fancier stylesheet.
The [official documentation](https://doc.sagemath.org/html/en/reference/plotting/sage/plot/plot.html) says:
> MATPLOTLIB STYLE SHEET OPTION:
>
> `stylesheet` - (Default: classic) Support for loading a full matplotlib style sheet.
> Any style sheet listed in matplotlib.pyplot.style.available is acceptable.
> If a non-existing style is provided the default classic is applied.
When I try it with a simple example, I get
plot(sin, stylesheet="ggplot")
...
RuntimeError: Error in line(): option 'stylesheet' not valid.
However I found that this alternative works:
plot(sin).show(stylesheet="ggplot")
This is ugly, because I use IPython CLI and want to be able to show the plot by this syntax
p = plot(sin)
p
without typing `.show()`.
Moreover, I'd like to configure my `.sage/init.sage` file so that the 'ggplot' stylesheet is used by default:
# .sage/init.sage
plot.options["stylesheet"] = "ggplot"
This doesn't work though, for sage substitutes this option into `line()` function which appears to have no such option.
**Questions:**
1. Is this a bug, or a mistake in (my understanding of) the documentation? Should it be reported and if yes, where is the best place to do it?
2. How do I achieve custom plotting style by default (perhaps by some setting in the `init.sage` file)?
I'm using SageMath version 9.5, Release Date: 2022-01-30 with Python 3.10.2, all downloaded from ArchLinux official repos.SageUserNickSun, 13 Feb 2022 12:44:24 +0100https://ask.sagemath.org/question/61081/