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, 17 Sep 2023 14:01:01 +0200How to plot the real line in SageMathhttps://ask.sagemath.org/question/73437/how-to-plot-the-real-line-in-sagemath/I am preparing a SageMath Jupyter notebook for expository purposes. I would like to be able to display the real line, with chosen points on it, and some arrows between certain pairs of points.
While this would be easy to do in LaTeX (by means of TikZ), I do not know how to do it in Sage. This feels like something that should be well within Sage's capabilities. What to do?
Let me give an easy, concrete example. Say I want to plot the points -5/11 + \beta, -4/11 + \beta,..., 5/11+\beta (labelled as such) on the real line, where $\beta = 1/50$ (for instance).
In a second version of the graph, I also want curved arrows going from -5/11+\beta to -4/11+\beta, from -4/11+\beta to -3/11+\beta, and so on until -2/11+\beta to -1+\beta; I also want a curved arrow from -1+\beta to 0.
How to do this?
Update: Let me include some (extremely amateurish) TikZ code, so that people can see exactly what I want:
\begin{tikzpicture}
\def\scale{2}
\def\bet{0.2}
\draw[-] (-\scale*3.5,0) -- (\scale*3.5,0);
\foreach \i in {-3,...,3} {
\draw[shift={(\scale*\i,0)},color=gray] (0pt,0pt) -- (0pt,-3pt) node[below] {$\frac{\i}{q}$};
\filldraw (\scale*\i+\scale*\bet,0) circle (2pt) node[above] {$\frac{\i}{q}+\beta$};
}
\foreach \i in {-3,...,-2} {
\draw[*->*] (\scale*\i+\scale*\bet-0.08,0.04) to[bend right] (\scale*\i+\scale*\bet+\scale+0.08,0.04);
}
\draw[*->] (-\scale+\scale*\bet-0.08,0.04) to[bend right] (0,0);
\end{tikzpicture}
I'd gladly include the result here, but I do not yet have enough points to upload files :(.
Of course I can just include the resulting image in my Jupyter notebook, but for some reason Jupyter is refusing to display vector graphics, and will display the image only if it is very low-resolution. Wouldn't it be nice if there were a way to do this within Sage...GaraldSun, 17 Sep 2023 14:01:01 +0200https://ask.sagemath.org/question/73437/Automatically adding colors to multiple list_plot graphicshttps://ask.sagemath.org/question/56240/automatically-adding-colors-to-multiple-list_plot-graphics/Is there a way to *automatically* color different plots?
For example, I'm trying to plot complex points using `list_plot`, and the points are all stored in a list of lists, each of which I would like to be a different color. So, in order to plot these points, I have
list=[list1,list2,...]
plot = sum(list_plot(i) for i in list)
I'm wondering if there's any (somewhat simple) way to add different colors corresponding to each list in an iterable fashion, rather than typing out
plot=list_plot([i for i in list1], rgbcolor='red')+list_plot([i for i in list2], rgbcolor='orange')+...elcardinFri, 19 Mar 2021 01:29:42 +0100https://ask.sagemath.org/question/56240/How to change the gridlines dimension?https://ask.sagemath.org/question/55797/how-to-change-the-gridlines-dimension/ plot(f, (x, 0.1, 1), figsize= 4, color= 'green', gridlines =True)
I want to use the change the default gridline spacing!
And add a proper box at the all the 4 edges of the Plot.
Could someone help ?
Thankskrrish0150Sun, 21 Feb 2021 15:48:44 +0100https://ask.sagemath.org/question/55797/custom viewer for view(), plot(), ...https://ask.sagemath.org/question/51522/custom-viewer-for-view-plot/ Hey,
when you view some object or plot some graph, then sage will start your system pdf viewer or image viewer.
My problem:
I use a tiling window manager (bspwm) and I want my pdf viewer and image viewer to start in floating mode if started by sage.
So is there a way of changing the commands of the execution of the pdf- and image-viewer?
(Or do you know any solution to my problem?)
Big thanks!
JohannjbirnickSat, 23 May 2020 20:55:38 +0200https://ask.sagemath.org/question/51522/draw all faces of alcoves (affine root system)https://ask.sagemath.org/question/45354/draw-all-faces-of-alcoves-affine-root-system/I am trying to plot alcoves for in a rank 3 affine root system with some of those alcoves highlighted by having all faces drawn and the others only shown as a wire frame.
The manual on visualising root systems at sagemath.org is quite useful, but I have some effects show that I don't understand.
For some reason while the fundamental alcove will have all faces shown many of the others have not, that is, some faces are missing. Below you find one example code that I have done. For the chosen seq one face is missing, the red one. For other choices of seq one might even see only one face drawn. How do I force to have all faces shown?
L = RootSystem(["A",3,1]).ambient_space()
P = RootSystem(["A",3,1]).weight_space(extended=True)
Lambda = P.fundamental_weights()
W = L.weyl_group()
W0=W.classical()
plot_options = L.plot_parse_options()
seq=[2,3,1,2]
t = 1*Lambda[1]-1*Lambda[2]+1*Lambda[3]
Alcoves=[W.from_reduced_word(w.reduced_word()) for w in W0]
p = L.plot_fundamental_chamber("classical")
p += L.plot_fundamental_weights()
p += L.plot_alcoves(alcoves=Alcoves, wireframe=True)
p += L.plot_alcoves(alcoves=[W.from_reduced_word(seq)])
p += L.plot_alcoves(alcoves=[W.from_reduced_word([])])
p += plot_options.family_of_vectors({t: L(t)})
p.show(frame=False)oloidThu, 07 Feb 2019 16:08:34 +0100https://ask.sagemath.org/question/45354/Can't display figureshttps://ask.sagemath.org/question/44953/cant-display-figures/hello,
i installed Sage on a new computer this morning,
but i can't display any figures.
That's the error i get :
> /home/xxx/Documents/SageMath/local/lib/python2.7/site-packages/sage/\
repl/rich_output/display_manager.py:592: RichReprWarning: Exception in
_rich_repr_ while displaying object: libtk8.6.so: cannot open shared
object file: No such file or directory
RichReprWarning,
Graphics object consisting of 1 graphics primitive
Anyone got an idea why?
i'm using the notebook of sagemaths
Thanks.tommeTue, 08 Jan 2019 12:15:39 +0100https://ask.sagemath.org/question/44953/Plotting in Sagehttps://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 19:46:39 +0100https://ask.sagemath.org/question/41250/Plot/Show Png/jpg in sagemath worksheethttps://ask.sagemath.org/question/40501/plotshow-pngjpg-in-sagemath-worksheet/Hello every one, I am testing sagemath for course creation. What is the fastest way to embeed png pictures and diplay them? Something like this: https://paper.dropbox.com/doc/Ubung-Lagebeziehung-Gerade-Gerade-NiPkMCucw7FeDxj15u6aZ?_tk=share_copylink thethaSat, 06 Jan 2018 16:44:00 +0100https://ask.sagemath.org/question/40501/Is it possible to embed a plot (or png) within another plot?https://ask.sagemath.org/question/34998/is-it-possible-to-embed-a-plot-or-png-within-another-plot/I have looked at the documentation for 2d plots without any success. I would like to know if it is possible to embed a plot within a plot.
I currently have a set of polygons and I would like to have plots of graphs embedded into each region. Something resembling the attached [image](/upfiles/14752402076305906.png).
Is it possible to achieve this using sagemath's plotting interface?
Thanks!fidbcFri, 30 Sep 2016 14:58:10 +0200https://ask.sagemath.org/question/34998/How to make pygraphviz and sage compatible?https://ask.sagemath.org/question/31070/how-to-make-pygraphviz-and-sage-compatible/ Hi,
I would like sage to help me when I am working with (un)directed graphs and quivers, and so on. After having played around with various possibilities, I would like to convert some stuff into a string and then let sage print something like a .ps - file that contains an image from dot (or something similar to this).
> Unfortunately, I came across the following issue(s) and have no idea what to do now. With the sage version I installed, there is python 2.x as a delivered package. But it seems that sage complains about python3, what doesn't make sense to me.
Could you help me understand and solve the following:
boehmler@boehmler-X55A:~/Schreibtisch/bb/sage-6.9-x86_64-Linux$ ./sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath Version 6.9, Release Date: 2015-10-10 │
│ Type "notebook()" for the browser-based notebook interface. │
│ Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
sage: import networkx as nx
sage: import matplotlib.pyplot as plt
sage: import matplotlib.image as mpimg
sage: from cStringIO import StringIO
sage: g = nx.dodecahedral_graph()
sage: d = nx.to_pydot(g)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-6-0d33c400a5cf> in <module>()
----> 1 d = nx.to_pydot(g)
AttributeError: 'module' object has no attribute 'to_pydot'
sage: d = nx.to_agraph(g)
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-7-d9254026fb59> in <module>()
----> 1 d = nx.to_agraph(g)
/home/boehmler/Schreibtisch/bb/sage-6.9-x86_64-Linux/local/lib/python/networkx/drawing/nx_agraph.pyc in
to_agraph(N)
132 raise ImportError('requires pygraphviz ',
133 'http://networkx.lanl.gov/pygraphviz ',
--> 134 '(not available for Python3)')
135 directed=N.is_directed()
136 strict=N.number_of_selfloops()==0 and not N.is_multigraph()
ImportError: ('requires pygraphviz ', 'http://networkx.lanl.gov/pygraphviz ', '(not available for Python3)')
sage:
Exiting Sage (CPU time 0m3.33s, Wall time 56m28.80s).
After typing
boehmler@boehmler-X55A:~/Schreibtisch/bb/sage-6.9-x86_64-Linux$ sudo -H pip install pygraphviz
I get the message
Wall -Wstrict-prototypes -fPIC -I/usr/include/graphviz -I/usr/include/python2.7 -c pygraphviz/graphviz_wrap.c -o build/temp.linux-x86_64-2.7/pygraphviz/graphviz_wrap.o
pygraphviz/graphviz_wrap.c:130:21: fatal error: Python.h: Datei oder Verzeichnis nicht gefunden
# include <Python.h>
^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
Command "/usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-6yZh3l/pygraphviz/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-a6o8Fg-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-6yZh3l/pygraphviz
in the end. I would be grateful for any hints how to solve / fix this.
Thanks for the help!
BernThu, 26 Nov 2015 03:42:50 +0100https://ask.sagemath.org/question/31070/Plot boxes have jumpy xy ranges in log scalehttps://ask.sagemath.org/question/26637/plot-boxes-have-jumpy-xy-ranges-in-log-scale/Note: this is an attempt to concisely rephrase the issue at
[ask-sage question 26623](http://ask.sagemath.org/question/26623/modifying-xmin-value-and-frame-of-a-plot/).
Plotting in log scale, the bounding box doesn't adjust well to xmin, xmax, ymin, ymax.
It seems that plot bounding boxes are set with increments not adapted to log scale.
The following example illustrates this jumpiness in certain ranges of values.
opt = { 'ymin': 1, 'ymax': 25, 'scale': ('loglog', 10), 'frame': True }
def p(a): return plot(x, xmin=a, xmax=25, **opt)
for a in (1.2, 2, 3, 4): p(a).show() # poor xmin for bbox
for a in (4.5, 7, 10, 14): p(a).show() # poor xmax for bbox
for a in (12, 14, 20, 23): p(a).show() # poor xmin and xmax
slelievreFri, 24 Apr 2015 14:36:38 +0200https://ask.sagemath.org/question/26637/Graph edge label: formatting possibilitieshttps://ask.sagemath.org/question/25448/graph-edge-label-formatting-possibilities/I have a graph with like this and would like to format ( e.g. color ) the edge labels more individual. Is it possible for example to make from 'a|b' the 'a' red and 'b' blue? Also different font types ( bold, italic ) etc would be interesting.
G = Graph(multiedges=True)
G.add_edges( [(0,1,'a|b'),(1,2,'c|d'),(2,3,'e|f'),(3,4,'g|h'),(4,0,'i|j')] )
H = G.plot(edge_labels=True, graph_border=True)
H.show()
When I remember correctly, there is (limited) support for TeX-formatting, could this be used somehow to achieve the formatting?herbFri, 09 Jan 2015 13:05:52 +0100https://ask.sagemath.org/question/25448/Graph: colored edge labelshttps://ask.sagemath.org/question/25413/graph-colored-edge-labels/I'm trying to plot a graph with labels on the edges as follows:
G = Graph(multiedges=True)
G.add_edges( [(0,1,'a'),(1,2,'b'),(2,3,'c'),(3,4,'b'),(4,0,'a')] )
H = G.plot(edge_labels=True, graph_border=True)
H.show()
Is it possible to color the edge labels, e.g. making the "a" red, "b" blue etc?
herbTue, 06 Jan 2015 20:10:47 +0100https://ask.sagemath.org/question/25413/How can I plot points given by code?https://ask.sagemath.org/question/25177/how-can-i-plot-points-given-by-code/ I want to plot the points, that I get from the following code all together in one plot. How can I do that?
for x in range(11):
for y in range(ceil(0.5*(x+4)),(2*x-3)):
print (x,y,x+y-2)
ThankslegehTue, 09 Dec 2014 16:11:30 +0100https://ask.sagemath.org/question/25177/modify axe scalehttps://ask.sagemath.org/question/10246/modify-axe-scale/Hello,
I would like to choose which numbers appear on the axes of a graphics. If I do
sage: G = Graphics()
sage: G.set_axes_range(xmin=0,xmax=10,ymin=0,ymax=1)
sage: G.show()
Then the x axis has a small separation each 2 (ie the numbers 0,2,4,6,8,10 appear). What should I do to get it 3 (ie separation at 0,3,6,9) ?
ThanksvdelecroixMon, 17 Jun 2013 10:31:08 +0200https://ask.sagemath.org/question/10246/How to plot a sparse graph with small cycles ?https://ask.sagemath.org/question/9957/how-to-plot-a-sparse-graph-with-small-cycles/Hello,
I have a sparse graph which have few cycles which moreover are small compared to the size of the graph. In other words, my graph looks like a tree. Is there a better way than the default to plot it ?
My graph is precisely the giant component of an random Erdös-Renyi graph with parameter just above 1 as in:
sage: G = graphs.RandomGNP(1000, 1.3 / 1000)
sage: cc = G.connected_components_subgraphs()
sage: giant_comp = cc[0]
On my computer, the default picture has a lot of overlaps:
sage: giant_comp.plot(vertex_labels=False, vertex_size=10)
VincentvdelecroixSat, 30 Mar 2013 10:52:16 +0100https://ask.sagemath.org/question/9957/Coloring edges by their labelshttps://ask.sagemath.org/question/9364/coloring-edges-by-their-labels/I'm trying to understand how to use the color_by_label parameter of the Graph.plot() function to set edge colors depending on various conditions. I cannot seem to get any colors to display other than cyan and red, no matter what I put in the edge labels, and, as in the linked image, I cannot seem to reliably get the colors to go with the labels.
In my example, I was trying to set edge color to blue if either of the vertices of an edge is odd, red otherwise.
(Sorry for the external link -- I apparently need to acquire some karma before I can post it here)
[Screen Shot of sage notebook session and graphics output](http://tinypic.com/r/ou5hxt/6)
version. Sage 5.0.1 on Mac OS X 10.8.1, notebook running in ChromemesriFri, 28 Sep 2012 17:39:41 +0200https://ask.sagemath.org/question/9364/Why does graph plotting crop so aggressively, and what is a work-around?https://ask.sagemath.org/question/8016/why-does-graph-plotting-crop-so-aggressively-and-what-is-a-work-around/Surely, the Sage community is aware of this bug. For example, there is [this ticket](http://trac.sagemath.org/sage_trac/ticket/7299), in which the problem is supposed to be fixed. But it's not!
A patch is described: in `sage/graphs/graph_plot.py` we can add the line(?)
> `G._extra_kwds['axes_pad']=.05 `
Am I to change this value in order to fix this over-zealous cropping behavior? No matter what I do, in this regard, I still end up with graph vertices partially cut off.
What's the easy work-around? I would like to be able to plot `graphics_array` objects with several graphs (with their vertices clearly shown!).
(http://trac.sagemath.org/sage_trac/ticket/7299)Sammy BlackMon, 21 Mar 2011 14:00:06 +0100https://ask.sagemath.org/question/8016/automatic zordering with plotshttps://ask.sagemath.org/question/7829/automatic-zordering-with-plots/The `zorder`-option can be used to specify on which layer the elements of a plot are drawn. Is there a way to automatically increase the z-order at each time an element is added to the current `Graphics`-object? (manually inserting `zorder=...` is not the solution I want, since it is inflexible (changing the code; shifting code-blocks around))
E.g.
g = Graphics()
g += point((0,0)) # I want zorder=1
g += point((1,0)) # I want zorder=2
# ...
Daniel KrennWed, 22 Dec 2010 10:35:54 +0100https://ask.sagemath.org/question/7829/Plot titleshttps://ask.sagemath.org/question/7808/plot-titles/I know about the text function, but this has to be inside the plot. How would one make titles for plots?
Thank you.Eviatar BachSun, 12 Dec 2010 01:22:02 +0100https://ask.sagemath.org/question/7808/