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, 28 Sep 2020 08:00:42 +0200Adapt 2D-plot tick label attributes to dateshttps://ask.sagemath.org/question/51080/adapt-2d-plot-tick-label-attributes-to-dates/Is there a way to access ticks labels to rotate them? I've tried `Graphics.matplotlib()` and `set_rotation()`, but this doesn't seem to produce changes. Am I doing wrong things?
In the example below, the formatter and locator are working correctly, but the problem is all labels are oriented horizontally, messing all together since each tick label is a date and therefore quite long. Need to rotate them.
import csv
from datetime import datetime
from matplotlib import ticker
from matplotlib import dates
data = [('04/22/20', '04/23/20', '04/24/20','04/25/20','04/26/20', '04/27/20'),
(20, 40, 80, 160, 320, 640)]
labels = data[0]
labels = map(lambda x: dates.date2num(datetime.strptime(x, '%m/%d/%y')), labels)
labels = list(labels)
values = data[1]
values = map(lambda x: int(x), values)
# Z is a list of [(x1, y1), (x2, y2)...]
# x1, x2, ... are dates
# y1, y2, ... are values
Z = zip(labels, values)
Z = list(Z)
p = list_plot(Z, ticks=[1, None],
tick_formatter=[dates.DateFormatter('%d.%m.%Y'), None],
axes_labels=['Days', '$\\log \\;{N}$'], plotjoined=True,
thickness=2, figsize=4, scale='semilogy')
G = p.matplotlib()
labels = G.axes[0].xaxis.get_ticklabels()
labels = list(labels)
for label in labels:
label.set_rotation(45)
p
This outputs the plot with an ugly x-axis on which all the dates are messed up. How to fix that?
![Plot with dates as tick labels on the x-axis](https://i.imgur.com/14VIFv4.png)MrDvbnhbqMon, 27 Apr 2020 20:59:05 +0200https://ask.sagemath.org/question/51080/Using base 10 exponent of a number as label in a contour plothttps://ask.sagemath.org/question/53631/using-base-10-exponent-of-a-number-as-label-in-a-contour-plot/ I am currently trying to improve the labelling of a contour plot. As contours I'm only using negative powers of ten, so I hope to have a simple LaTeX label of the form, say, 10^{-23}. My starting point was one of the examples at the help page for contour_plot (here was the link to the sage documentation). After various failed attempts with log(x, 10), I found in the question "Integer types and log()" (that would be question id(?) 28679/integer-types-and-log) an example using valuation(x,10). However, the results seem odd. Below the slightly simplified thing I try to plot.
var('x y')
rp = 6.77048070412999e-10*(x + sqrt(x^2-y^2*x^2))
sigma0 = 1.44008750449331e-18*(3*x + sqrt(9*x^2 - 8*y^2*x^2))^4/(8*(3*x^2 - 2*y^2*x^2 + x*sqrt(9*x^2 - 8*y^2*x^2)))
f(x,y) = (1.12469227142351e-70*y*x^2/(rp)^6*exp(-(rp)^2/(sqrt(y)*x*0.169262017603250))-1.65389403372211e-162*(sqrt(x^2-y*x^2))^3*sigma0*(x-2*sqrt(x^2-y*x^2))/(rp)^10)
contour_plot(f(x,y), (x,0,100), (y,0,1), contours=[0,1e-25,1e-24,1e-23,1e-22,1e-21,1e-20,1e-19],aspect_ratio='automatic',labels=True, label_fmt=lambda x: r'''$10^{-%s}$'''%(valuation(1/x,10)), fill=False)
If I do this, I get 10^{-0} for several contours.
So, I checked, what valuation does to the numbers:
print(valuation(1/(1e-19),10))
print(valuation(1/(1e-20),10))
print(valuation(1/(1e-21),10))
print(valuation(1/(1e-22),10))
print(valuation(1/(1e-23),10))
yielding
19
20
0
22
0
If I'm using something like
label_fmt=lambda x: r'''$10^{-%s}$'''%(log(1/x,10))
instead, I get only the message "Graphics object consisting of 1 graphics primitive", and
label_fmt=lambda x: r'''$10^{-%s}$'''%(log(Integer(1/x),10))
yields another plot with odd labels - which have the odd behaviour at the same exponents as the example with "valuation", but I don't know why.
I'm currently doing this mostly in a jupyter notebook on Windows 10 with Sage 9.1.
Am I misunderstanding the use of "valuation" or log(x,10) in this case? Did I run into a bug? How can I get the exponents I'm after?Wraith-of-SethMon, 28 Sep 2020 08:00:42 +0200https://ask.sagemath.org/question/53631/How to add string tick labels to 2D plots?https://ask.sagemath.org/question/9945/how-to-add-string-tick-labels-to-2d-plots/Hi folks, i want to add string tick labels to a 2D plot, e.g. `['$100', '$200', '$300']` on the x-axis instead of the ticks `[1, 2, 3]`. I see from [http://stackoverflow.com/questions/5439708/python-matplotlib-creating-date-ticks-from-string](http://stackoverflow.com/questions/5439708/python-matplotlib-creating-date-ticks-from-string) that i can do this with matplotlib via
from matplotlib import pyplot as plt
plt.plot([1,2,3],[3,4,3])
ax = plt.gca()
ax.set_xticks([1,2,3])
ax.set_xticklabels(['$100','$200','$300'])
Is there a Sage way to accomplish the same thing?
Personally, i find Sage plotting commands more user-friendly than matplotlib commands.araichevSun, 24 Mar 2013 18:48:21 +0100https://ask.sagemath.org/question/9945/Legend_fonts in list of plotshttps://ask.sagemath.org/question/49960/legend_fonts-in-list-of-plots/ Hello there,
I want to make an array of plots, and I need the font size for the legends to be reduced. I tried the code below and some variants.I really don't see what is wrng, when I try the `().set_legend_options(font_size = 8)` on a single curve, everything works fine. I tried doing this while running through a list, but did not work.
var('t')
C=[2.5, 1.7, 1, 0.7, 0.5, 0.2, 0, -0.2, -0.5, -0.8, -1, -2] # The values for c
Curves = [polar_plot(1+c*sin(t),0,t,2*pi,
legend_label = '%s'%c.n(digits=2)).set_legend_options(font_size = 8) for c in C]
Array = graphics_array(((Curves[0],Curves[2], Curves[2], Curves[3]),
(Curves[4],Curves[5], Curves[6], Curves[7]),
(Curves[8],Curves[9], Curves[10], Curves[11])))
Array.show(figsize = 9)
Thanks in advance!
JCTue, 18 Feb 2020 03:45:17 +0100https://ask.sagemath.org/question/49960/Add labels to x/y axeshttps://ask.sagemath.org/question/47348/add-labels-to-xy-axes/ Hi!
I'm ploting a list of points, and I would like to add labels under the X and Y axes with the physical units in horizontal and vertical (i.e. days and cells/mL).
This is the command line:
a=list_plot(zip(t,T1),axes_labels=['$t$','$T(t)$'])
Thank you!miguelFri, 02 Aug 2019 12:56:59 +0200https://ask.sagemath.org/question/47348/Cell label resethttps://ask.sagemath.org/question/40336/cell-label-reset/What is the proper way to reset the cell number in a notebook cell?
When I evaluate all the cells of a notebook I want to always start with the number In[1] as the first cell label of the notebook in order to have a predictable number of all the subsequent cells, something like kill(labels) in Maxima.
danielvolinskiThu, 28 Dec 2017 11:59:31 +0100https://ask.sagemath.org/question/40336/previous fontsize settings in plot now produce huge fontshttps://ask.sagemath.org/question/29464/previous-fontsize-settings-in-plot-now-produce-huge-fonts/I have been using p.fontsize(20) a lot, but since the upgrade to 6.8, the same setting now produces HUGE font sizes, making the axes labels exceed the figure sizes. I wonder what happened there and how this could be fixed.
I believe that some of the reason is the introduction of the new option axes_labels_size as mentioned here:
http://ask.sagemath.org/question/26807/how-do-i-adjust-the-size-of-axes-labels-and-figure-titles-in-plots/
Try this in a sage version before 6.7 and after 6.7:
P = plot(x^2, 0,2)
P.axes_labels(['Some value of x', 'Resulting value of y'])
P.fontsize(20)
P
Is there a way to put a one-liner at the start of my worksheets to get back the old behaviour without having to modify all P.fontsize(20) lines?
stanWed, 16 Sep 2015 14:57:35 +0200https://ask.sagemath.org/question/29464/Size of Labels on a Plothttps://ask.sagemath.org/question/7518/size-of-labels-on-a-plot/dear all:
I'd like to know if there is any way to change the size of the font of labels (in a plot) without changing the size of the numbers on the ticks.
Thank youDoxMon, 08 Apr 2013 13:42:04 +0200https://ask.sagemath.org/question/7518/2d plot axes labelshttps://ask.sagemath.org/question/9235/2d-plot-axes-labels/Hello,
How do I add labels (names) to my axes when doing a simple 2d plot such as:
t = var('t')
E(t)=(10.40*(1-exp(-0.25*t)))^2.81
plot(E,t,(x,0,15))
I would like to do so the labels are aligned directly under the x axis and vertically over the y axis. Is there a way?brenogilTue, 14 Aug 2012 15:20:31 +0200https://ask.sagemath.org/question/9235/2 Plotting Questionshttps://ask.sagemath.org/question/7851/2-plotting-questions/I have been able to get most things working with:
list_plot([(r,Pabrf(Ratio=r).n()) for r in srange(-1, 1, 0.1, include_endpoint=True)], plotjoined=True, frame=true, ymin=0,axes_labels=('$\Omega _{0}/\omega _{nut}$',"$ P _{a\rightarrow b}$"),ticks=[[-1, -0.5,0,0.5,1],[0.2,0.4,0.6,0.8,1.0]])
I have an additional questions about controlling plot features:
1. How do I turn off or turn on the lines at the origin(0)? I can find nothing in the Matplotlib docs that mentions this.
2. How do I get the \rightarrow to display instead of the \Rightarrow? The \Rightarrow, \dashrightarrow and \longrightarrow display properly, I think this a bug.
Thank you again for your help.mhfreyFri, 07 Jan 2011 10:44:15 +0100https://ask.sagemath.org/question/7851/