ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 26 Aug 2019 09:02:04 -0500How to draw the following graphhttp://ask.sagemath.org/question/47594/how-to-draw-the-following-graph/I want to write the following code in sagemath but unable to write it:
Suppose we consider the group $\Bbb Z_n$.
We consider an element $a\in \Bbb Z_n$ and form the subgroup generated by $a$ i.e. $\langle a\rangle =\{a,2a,3a,\ldots 0\}.$
We form a graph $G$ whose vertices are $\langle a\rangle $ and $\langle a\rangle $ and $\langle b\rangle $ are adjacent if either $\langle a\rangle \subset \langle b\rangle $ or $\langle b\rangle \subset \langle a\rangle $ .
How to plot the graph $G$ is Sagemath?
I am giving an example to clear the question:
Consider $\Bbb Z_4$ then consider $\langle 0\rangle $, $ \langle 1\rangle$ , $ \langle 2\rangle$, $ \langle 3\rangle$
Clearly $\langle 0\rangle =\{0\}$, $ \langle 1\rangle=\{1,2,3,0\}$ , $ \langle 2=\{2,0\}\rangle$, $ \langle 3=\{0,1,2,3\}\rangle$.
Thus the graph $G$ has vertices as $\langle 0\rangle $, $ \langle 1\rangle$ , $ \langle 2\rangle$, $ \langle 3\rangle$ and
$\langle 0\rangle $ is adjacent to $ \langle 1\rangle$ , $ \langle 2\rangle$, $ \langle 3\rangle$,
$\langle 1\rangle $ is adjacent to $ \langle 2\rangle$ , $ \langle 0\rangle$,
$\langle 2\rangle $ is adjacent to $ \langle 1\rangle$ , $ \langle 0\rangle$, $ \langle 3\rangle$
and $\langle 3\rangle $ is adjacent to $ \langle 0\rangle$, $ \langle 2\rangle$
Thus $G$ becomes
https://imgur.com/Ef9P4uzCaptchaMon, 26 Aug 2019 09:02:04 -0500http://ask.sagemath.org/question/47594/How to plot points of size less than 1?http://ask.sagemath.org/question/47573/how-to-plot-points-of-size-less-than-1/I have a huge sequence L (say of length $n=10^6$) and I would like to plot all the points (i,L[i]) for i in range(n).
To do so, the following works.
points([(i,L[i]) for i in range(n)],size=1)
The problem is that `size=1` (for the points) is too large for a satisfactory plotting.
But if $r$ is a fixed float with $0< r <1$, then
points([(i,L[i]) for i in range(n)],size=r)
is interpreted as
points([(i,L[i]) for i in range(n)],size=0)
which is an empty plotting (so not working).
**Question**: How to rewrite the second command line above to really plot points of `size=r`?Sébastien PalcouxFri, 23 Aug 2019 01:09:04 -0500http://ask.sagemath.org/question/47573/Conditional Plot, plot f(x+iy) if g(x+iy) satisfies some kind of conditionhttp://ask.sagemath.org/question/45445/conditional-plot-plot-fxiy-if-gxiy-satisfies-some-kind-of-condition/Let's say I have two functions f(zeta) and g(zeta), and I'd like to have 3D-plot and Contour Plot of f(zeta) if g(zeta) in a certain range.
I have defined f(zeta) and g(zeta), and then I tried this command, but Sage said the syntax is not valid.
B=implicit_plot(lambda x,y : float(f(x+y*I)),if 1<g(x+y*I)<3,(-5,5),(-5,5)))
I am pretty new with Sage math, so please bear with me if the question is too trivial....
JacobsonRadicalWed, 13 Feb 2019 04:55:53 -0600http://ask.sagemath.org/question/45445/__init__() takes exactly 5 arguments (4 given) error in contour plothttp://ask.sagemath.org/question/45446/__init__-takes-exactly-5-arguments-4-given-error-in-contour-plot/ I am trying to make a contour plot of a complex valued function. Let say it is g(z).
I have imported the complex root and ContourPlot command by doing following:
from sage.rings.polynomial.complex_roots import complex_roots
from sage.plot.contour_plot import ContourPlot
I have even successfully plot the 3d-Plot, but I encountered an error stating:
__init__() takes exactly 5 arguments (4 given)
My command is:
C=ContourPlot(lambda x,y:float(green(x+y*I)),(-5,5),(-5,5))
It seems that I did not miss the fifth argument, I tried to add in some commands, such as plot_points, but then Sage said it did not expect these commands..
What did I miss? Thank you!!JacobsonRadicalWed, 13 Feb 2019 05:03:37 -0600http://ask.sagemath.org/question/45446/MatrixPlots with cell entrieshttp://ask.sagemath.org/question/41234/matrixplots-with-cell-entries/ Is there a nice way to combine `MatrixPlot` with something else to have a label in each cell such as in this picture?
![image description](https://i.stack.imgur.com/bgNdN.png)jepstraThu, 22 Feb 2018 11:19:50 -0600http://ask.sagemath.org/question/41234/Plotting in Sagehttp://ask.sagemath.org/question/41250/plotting-in-sage/I have some numbers in two separate arrays, and I want to plot them in such a way that the end result looks more or less like this:
![image description](/upfiles/15194978051374454.png)
Currently, I have a code that looks like this:
res_blue = [...] # data for the blue circles (removed for brevity)
res_red = [...] # data for the red crosses (removed for brevity)
list_plot(res_red, color='red')
But, instead the above code generates only plot with red dots. How can I combine the two arrays in the same plot, choose their color and the shape to be put in the plot?ninhoSat, 24 Feb 2018 12:46:39 -0600http://ask.sagemath.org/question/41250/Drawing all paths from (0, 0) to (n, n) moving one unit right or uphttp://ask.sagemath.org/question/33201/drawing-all-paths-from-0-0-to-n-n-moving-one-unit-right-or-up/This question is just the same as [this one](http://mathematica.stackexchange.com/questions/112395/how-to-draw-all-paths-from-1-1-to-n-n-by-move-1-0-or-0-1) made for Mathematica. I saw it and I was trying to reproduce it in Sage just for fun, but it's getting longer than I like and I would love to know your approach in Sage. I think it's a great way to learn. This is half of my try:
n=3
A=sum(line([(j, i), (n, i)]) for j in range(n+1) for i in range(n+1))
B=sum(line([(i, j), (i, n)]) for j in range(n+1) for i in range(n+1))
G = Graphics()
G += A + B
G.show(figsize=[4,4], axes=False)
result = []
combinations = [bin(i)[2:] for i in range(1, int('111111', 2))]
for num in combinations:
valid = ''.join(['0']*(6-len(num))) + num
zeros = valid.count('0')
ones = valid.count('1')
if zeros == 3 and ones == 3:
result.append(str(valid))
#At this point all the paths are stored in the variable 'results' in binary form.
#For example '010101' means right, left, right, left, right, left
paths = [[]]
for element in result:
path = []
for index, direction in enumerate(list(element)):
if direction == '0':
path.append((index, index - 1))
else:
path.append((index - 1, index))
paths.append(path)
At this point the list of list called paths is not well constructed. I realized I would have to put some `if` statements to make it work but I'm losing motivation in my solution because it's getting ugly and I don't think is very efficient.
How would you do it?
TARSFri, 22 Apr 2016 22:08:30 -0500http://ask.sagemath.org/question/33201/Insert image into Graphics objecthttp://ask.sagemath.org/question/32417/insert-image-into-graphics-object/ Is it possible to insert an image (let's say, a PNG file) into a Graphics object containing some plots?
I need to create a raster inset into a figure with the list_plot'ted curves.v_2eTue, 02 Feb 2016 06:37:32 -0600http://ask.sagemath.org/question/32417/Normalized coordinates for plots/graphics?http://ask.sagemath.org/question/25357/normalized-coordinates-for-plotsgraphics/ Is it possible to use normalized (unit) coordinates for graphics?
I would like to position a text label below the x-axis of a plot. Something like this:
po = plot(...)
po += text( (r'$mylabel$', (.5, -.1))
Where (.5, -.1) are coordinates relative to the bounding box of the plot with the extends (0..1,0..1). So yes, this is a very simple coordinate transformation. Do I have to do it by hand?
And if so, how do I get the actual bounding box of the plot?bitfixMon, 29 Dec 2014 08:46:33 -0600http://ask.sagemath.org/question/25357/