Ask Your Question

MrDvbnhbq's profile - activity

2023-08-09 19:35:31 +0200 received badge  Famous Question (source)
2021-04-30 21:04:28 +0200 received badge  Notable Question (source)
2021-02-16 04:05:03 +0200 received badge  Popular Question (source)
2020-04-28 22:27:40 +0200 commented answer Adapt 2D-plot tick label attributes to dates

Aha!.. That's a pretty nice solution. Will definitely dig deeper into pandas too. Thanks a lot for your help! Cheers 👍

2020-04-28 21:35:07 +0200 commented question Adapt 2D-plot tick label attributes to dates

Yes, thanks for this answer. I've already tried that with the same result. But this example is for pure matplotlib, not the sage Graphics object. I would like to know, what does that matplotlib() exactly do? I even tried:

from matplotlib.pyplot import figure
...   
fig = figure()
fig = p.matplotlib(fig)
...

to draw the plot on the new figure provided, but this doesn't work for me. So, the question is, is this matplotlib() function supposed to give the access to p attributes, which were previosly set when the plot was created, and should the changes made on the figure effect onto the plot? And is the plot is supposed to be redrawn on the new figure when the plot is passed as an argument to matplotlib()?

2020-04-28 16:16:26 +0200 received badge  Student (source)
2020-04-28 12:35:56 +0200 answered a question 3D graphics, contour plot and labels

I'm new to Sage, but it looks like I could answer to 1) and 2)

1) and 2) You can do this by using $ ....... $ inline syntax

2) Please refer to ticks, tick_formatter parameters description, you just pass a list of ticks labels to it, please see the description here: http://doc.sagemath.org/html/en/reference/plotting/sage/plot/graphics.html?highlight=tick_formatter.

Example:

 sage: plot(x**2, (x,0,2), ticks=[[1,2], None], tick_formatter=[["$x_1$","$x_2$"], None])
 Graphics object consisting of 1 graphics primitive
2020-04-28 12:33:34 +0200 commented question Adapt 2D-plot tick label attributes to dates

Hello, thank you for your response. I've added the information needed to comply.

2020-04-28 12:26:40 +0200 received badge  Editor (source)
2020-04-27 21:08:44 +0200 commented answer How to add string tick labels to 2D plots?

If that would be a better way to ask questions, https://ask.sagemath.org/question/51080/how-to-change-ticks-labels-attributes-for-the-2d-plot/

Any help is much appreciated.

2020-04-27 20:59:05 +0200 asked a question 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

2020-04-27 14:23:30 +0200 answered a question How to add string tick labels to 2D plots?

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?

# Z is a list of [(x1,y1),(x2,y2)...]
# x1,x2 are dates
# The formatter and locator are working correctly, but the problem is all labels are oriented horizontally, messing all together. Need to rotate them
p = list_plot( Z, ticks=[10, None], tick_formatter=[dates.DateFormatter('%d.%m.%Y'), None], axes_labels=[ 'Days', '$\\log \\;{N}$' ], scale='semilogy' )

G = p.matplotlib()
labels = G.axes[0].xaxis.get_ticklabels()
labels = list(labels)

for label in labels:
    label.set_rotation(45)