ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 08 Oct 2020 18:50:44 -0500How to set the matplotlib backend used by plot()https://ask.sagemath.org/question/53794/how-to-set-the-matplotlib-backend-used-by-plot/SageMath uses `matplotlib` as its graphics engine and the module itself can work with many backends. But how can I set a GUI matplotlib backend to be used by the `plot()` function and its friends, at least in the command-line interface? And is there a way to set a default backend?
In my setup, `plot()` doesn't respect the backend set by the `%matplotlib` magic, but `matplotlib.pyplot.plot()` does. Even worse, the default backend creates a PNG image file and opens it in the system's viewer.
I'm on macOS 10.13 "High Sierra" running SageMath 9.1, the binary app version.leogamaThu, 08 Oct 2020 18:50:44 -0500https://ask.sagemath.org/question/53794/Set LaTeX fontsize in labels?https://ask.sagemath.org/question/26273/set-latex-fontsize-in-labels/The size of the text:
plot(sin, 0, pi, legend_label='$sin(x)$', fontsize=28)
plot(sin, 0, pi, legend_label='$sin(x)$').show(fontsize=28)
differs for the parts rendered using LaTeX (i.e. they are not affected by the fontsize size, $sin(x)$ is still a small text). How can I specify font for the LaTeX parts of the labels?EugeneFri, 20 Mar 2015 15:54:59 -0500https://ask.sagemath.org/question/26273/GUI backend MATPLOTLIB in Sagehttps://ask.sagemath.org/question/11347/gui-backend-matplotlib-in-sage/Dear all,
- UPDATED:
How can one **export** the data (a object) 'matplotlib.figure.Figure' the namespace of Sagemath to IPython? Can the data be saved in a format (**not** png, pdf, etc.) that can be opened in IPython using the function **show()**?
Here is a related [Question](http://ask.sagemath.org/question/816/how-to-use-tk-on-sage). I have followed [this instruction](http://wiki.sagemath.org/sage_matlab) step by step, every step was successfully executed without any error report/message. However I couldn't invoke TkAgg as Backend of Sagemath nor IPython.
----------
Has SAGE a GUI back-end as MATPLOTLIB, on which one can **zoom, select points** etc.?
for example,
sage: bodes['entire']
<matplotlib.figure.Figure at 0x91ac950>
sage: bodes['entire'].show()
# It doesn't work and a Warning occurs.
/opt/sagemath/sage-6.1.1-x86_64-Linux/local/lib/python2.7/
site-packages/matplotlib/figure.py:362: UserWarning: matplotlib is
currently using a non-GUI backend, so cannot show the figure
"matplotlib is currently using a non-GUI backend, "
sage: f = bodes['entire']
sage: f.savefig('./figures/entire.png')
# I can only save my plotting in formats : png, pdf, etc..
----------
Thank you all in advance!
gundamlhTue, 25 Mar 2014 00:45:29 -0500https://ask.sagemath.org/question/11347/plot grids in a figurehttps://ask.sagemath.org/question/10779/plot-grids-in-a-figure/Dear all,
I want to plot grids in my plot.
I couldn't find any keyword like 'grid' in the help document of 'plot()' <function sage.plot.plot.plot>, and hence I tried [NUMERICAL PLOTTING](http://www.sagemath.org/doc/reference/plotting/sage/plot/plot.html):
sage: from pylab import *
sage: t = arange(0.0, 2.0, 0.01)
sage: s = sin(2*pi*t)
sage: P = plot(t, s, linewidth=1.0)
sage: xl = xlabel('time (s)')
sage: yl = ylabel('voltage (mV)')
sage: t = title('About as simple as it gets, folks')
sage: grid(True)
sage: savefig(os.path.join(SAGE_TMP, 'sage.png'))
sage: P
[<matplotlib.lines.Line2D at 0x7e0a050>] # stored in RAM?
but nothing came out... OK, how can I check if SAGE can call Matplotlib in my OS (openSuSE 12.3) correctly? I have installed and updated 'matplotlib' for Python 2.7 via YaST2.
Thanks in advance!gundamlhTue, 26 Nov 2013 03:40:36 -0600https://ask.sagemath.org/question/10779/How can I determine or control a plot's display scale?https://ask.sagemath.org/question/10722/how-can-i-determine-or-control-a-plots-display-scale/Suppose I do something like
p = plot(sin(x), (x,0,2*pi))
p.save("/tmp/plot.png")
Is there some way of knowing (or even better, controlling) *exactly* the scale of the saved image in pixels per axis unit (in each direction)?
For example, if I wish to write a second graph to a different png file at exactly the same scale, is there some way to do this?
Or, to put it differently, instead of specifying the size of the output png file in inches using `figsize`, I wish to specify the size in inches (or pixels) *per graph unit*.
[This matplotlib tutorial](http://matplotlib.org/users/transforms_tutorial.html) seems to be about what interests me, but I don't understand how Sage relates to matplotlib, and how I can access the `transData` field, let alone control its value.Gro-TsenSun, 10 Nov 2013 12:19:13 -0600https://ask.sagemath.org/question/10722/How can I add arrows at the end of sage plot axis?https://ask.sagemath.org/question/10178/how-can-i-add-arrows-at-the-end-of-sage-plot-axis/Hello everybody!
I have my plot:
import matplotlib.pyplot as plt
plt.clf()
fig = plt.figure()
plot(f(x), (0, 2*pi)).matplotlib(figure = fig)
plt.savefig('')
plt.close()
I want to add arrows at the end of this graph (as on [this image](http://commons.wikimedia.org/wiki/File:Conic_x%5E2%2B2xy%2By%5E2%E2%88%928x%3D0.svg)). But I can't do this. Help me please.AndreWinFri, 31 May 2013 09:59:16 -0500https://ask.sagemath.org/question/10178/Matplotlib curve is out of axes boundarieshttps://ask.sagemath.org/question/9249/matplotlib-curve-is-out-of-axes-boundaries/I am using matplotlib to plot some figures. But after update from sage 4.8 to sage 5.2, I get some "tails" out of axes boundaries. How to turn it off?
![image description](http://storage9.static.itmages.ru/i/12/0817/h_1345171595_1331745_e4184f0a59.png)
Thanks!koteThu, 16 Aug 2012 16:49:11 -0500https://ask.sagemath.org/question/9249/Vertical and horizontal span on plotshttps://ask.sagemath.org/question/9200/vertical-and-horizontal-span-on-plots/Hello!
Is there a way to add a vertical or horizontal span to a plot in Sage?
I need something similar to *axhspan()* and *axvspan()* functions in Matplotlib ([example](http://matplotlib.sourceforge.net/examples/pylab_examples/axhspan_demo.html)).
Thank you!v_2eFri, 03 Aug 2012 01:11:06 -0500https://ask.sagemath.org/question/9200/Plot Series of 3D Direction Vectors (Not All from Origen)https://ask.sagemath.org/question/9172/plot-series-of-3d-direction-vectors-not-all-from-origen/Hi,
I'm trying to plot a series of vectors. I've pasted what I have below. The problem is that I want to plot the second vector, starting from the end of the first vector. If I run the commands below, I get two vectors plotted as I want (with arrows) but they are both from the origin.
I tried looking at MATPLOTLIB to see what to do but I got stuck.
Is there an easy way to plot a series of vectors in the way that I want?
a=vector([1,1,1])
b=vector([2,2,3])
aPlot=plot(a, legend_label='Vector a')
bPlot=plot(b, legend_label='Vector b')
AllPlot=aPlot+bPlot
AllPlot.show()
Justin1Sun, 22 Jul 2012 07:52:05 -0500https://ask.sagemath.org/question/9172/Is there any way to title a plot? Or can you display matplotlib graphs in sage?https://ask.sagemath.org/question/9021/is-there-any-way-to-title-a-plot-or-can-you-display-matplotlib-graphs-in-sage/I know you can in matplotlib, but I can't find out how to do it with sage. I can make a graph with a title in matplotlib, but I'm not sure how to get it to display in a notebook.
**EDIT:** of course I found the answer right after posting this. pyplot.savefig displays the image.ooglybooglyFri, 01 Jun 2012 09:01:36 -0500https://ask.sagemath.org/question/9021/combine sage plot with matplotlibhttps://ask.sagemath.org/question/8273/combine-sage-plot-with-matplotlib/As some others I'm also searching for a convenient way for merging sage Graphics and figures from matplotlib.
Actually I don't understand why this is so difficult since Sage uses matplotlib internally. Nevertheless there seems to be no way for combining plots from both packages.
The best way would be to wrap a matplotlib plot into a Sage Graphics object.
I really love Sage's plot(...)+plot(...) syntax, but unfortunately there are some important plot types missing (e.g. errorbar plot). Of course one can do all plotting in matlotlib, but it would be more convenient to handle sage objects.
I saw in the sage documentation that one can get a matplotlib figure from a Graphics object, but didn't found a way to draw on it with matplotlib.
Does anyone know any way for combining plots from those packages?buergiSun, 14 Aug 2011 09:39:54 -0500https://ask.sagemath.org/question/8273/no more inline matplotlib plots in sage notebookhttps://ask.sagemath.org/question/8608/no-more-inline-matplotlib-plots-in-sage-notebook/Hi,
I can't get any matplotplib/pylab plots inline in a notebook. Plots now are created as pdf files that open in another window.
For example, the code below used to create the plot in a new box after the instruction plt.savefig('.')
import numpy as np
import pylab as plt
x = np.arange(-2 * np.pi, 2 * np.pi,0.1)
plt.figure(1)
plt.clf()
plt.plot(x, np.sin(x), label='sin(x)')
plt.savefig('.')
now it returns a link '.pdf' to a pdf file.
Using
plt.savefig('a.png')
returns the following traceback:
Traceback (most recent call last):
File "", line 1, in <module>
File "/private/var/folders/k7/k7XHz3-82RazCk+kNOj55U+++TM/-Tmp-/tmpjD4zHK/___code___.py", line 14, in <module>
exec compile(u"plt.savefig('a.png')" + '\n', '', 'single')
File "", line 1, in <module>
File "/tmp/sage-mac-app/local/lib/python2.6/site-packages/matplotlib/pyplot.py", line 363, in savefig
return fig.savefig(*args, **kwargs)
File "/tmp/sage-mac-app/local/lib/python2.6/site-packages/matplotlib/figure.py", line 1084, in savefig
self.canvas.print_figure(*args, **kwargs)
File "/tmp/sage-mac-app/local/lib/python2.6/site-packages/matplotlib/backend_bases.py", line 1853, in print_figure
print_method = self._get_print_method(format)
File "/tmp/sage-mac-app/local/lib/python2.6/site-packages/matplotlib/backend_bases.py", line 1793, in _get_print_method
'%s.' % (format, ', '.join(formats)))
ValueError: Format "png" is not supported.
Supported formats: pdf.
I don't know what settings changes I may have done, and couldn't find any documented help format settings in sage for matplotlib plots. Interestingly I used to experience before the impossibility to export sage generated plots in pdf... It would be nice to have a better control on these settings.
Thank you for any help
Samuel
sbottWed, 04 Jan 2012 22:23:41 -0600https://ask.sagemath.org/question/8608/Plotting arrows at the edges of a curvehttps://ask.sagemath.org/question/7958/plotting-arrows-at-the-edges-of-a-curve/How could I plot a plane curve (either the graph of a function or an implicit plot) so that where the curve leaves the bounds of the plot, an arrow in the tangent direction is added?
I'm trying to produce plots for quiz and exam questions that are similar to ones you see in many calculus books where arrows are added to the ends of the curve to indicate that the curve continues in a certain direction "off the screen".
I've searched sage-support, the manual, and the documentation without much success. Perhaps I'm searching for the wrong term. Searching for "arrow" and "plot" or "curve" hasn't gotten me anywhere. I've also looked through examples in the matplotlib gallery, but I don't see any examples of what I want there.
I can imagine writing code myself to add such arrows to a plot, but I'm sure someone has thought about and implemented this before.benjaminfjonesSat, 19 Feb 2011 14:11:26 -0600https://ask.sagemath.org/question/7958/