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.Tue, 15 Feb 2022 16:15:27 +0100TeX 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/Adapt 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/