Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to change ticks labels attributes for the 2D plot?

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. Need to rotate them.

# Z is a list of [(x1,y1),(x2,y2)...]
# x1,x2 are dates
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)

p

This outputs the plot with an ugly x-axis on which all the dates are messed up. How to fix that?

How to change ticks labels attributes for the 2D plot?

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. Need to rotate them.

# Z is a list of [(x1,y1),(x2,y2)...]
# x1,x2 x1, x2, ... are dates
# y1, y2, ... are values
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 = zip(labels, values)
Z = list(Z)

p = list_plot( Z, ticks=[10, 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?

How to change ticks labels attributes for the 2D plot?

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. Need to rotate them.

# Z is a list of [(x1,y1),(x2,y2)...]
# x1, x2, ... are dates
# y1, y2, ... are values
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?

How to change ticks labels attributes for the 2D plot?

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. 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

How to change ticks labels attributes for the 2D plot?

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. 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

How to change ticks labels Adapt 2D-plot tick label attributes for the 2D plot?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? things?

In the example below below, the formatter and locator are working correctly, but the problem is all labels are oriented horizontally, messing all together. 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/22/20', '04/23/20', '04/24/20','04/25/20','04/26/20', '04/27/20' ), '04/27/20'),
        (20, 40, 80, 160, 320, 640) ]
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, y1), (x2, y2)...]
# x1, x2, ... are dates
# y1, y2, ... are values
Z = zip(labels, values)
Z = list(Z)

p = list_plot( Z, list_plot(Z, ticks=[1, None], None],
              tick_formatter=[dates.DateFormatter('%d.%m.%Y'), None], axes_labels=[ 'Days', None],
              axes_labels=['Days', '$\\log \\;{N}$' ], plotjoined=true, \\;{N}$'], plotjoined=True,
              thickness=2, figsize=4, scale='semilogy' )
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-axisPlot with dates as tick labels on the x-axis