While the "ticks=" option in plot can be used to place custom tick marks on plot axes, how would you go about putting custom labels on each tick mark, preferably latex ones,. e.g. $x_0$, $x_1$, etc.
Is there a way of doing this automatically, given a list of ticks and labels?
While the "ticks=" option in plot can be used to place custom tick marks on plot axes, how would you go about putting custom labels on each tick mark, preferably latex ones,. e.g. $x_0$, $x_1$, etc.
Is there a way of doing this automatically, given a list of ticks and labels?
While the "ticks=" option in plot can be used to place custom tick marks on plot axes, how would you go about putting custom labels on each tick mark, preferably latex ones,. e.g. $x_0$, $x_1$, etc.
Is there a way of doing this automatically, given a list of ticks and labels?
While the "ticks=" option in plot can be used to place custom tick marks on plot axes, how would you go about putting custom labels on each tick mark, preferably latex ones,. e.g. $x_0$, $x_1$, etc.
Is there a way of doing this automatically, given a list of ticks and labels?
While the "ticks=" option in plot can be used to place custom tick marks on plot axes, how would you go about putting custom labels on each tick mark, preferably latex ones,. e.g. $x_0$, $x_1$, etc.
Is there a way of doing this automatically, given a list of ticks and labels?
Sorry about the replys above. This new Google groups interface is really confusing.
Anyway, I coded up a plot_labels function to make adding labels to plots a little more modular.
The function basically creates an empty axis with labels which can be attached to other plots. Code follows:
==========================
def plot_labels(x_ticks,x_labels,y_ticks,y_labels,fontsize=12):
import matplotlib.ticker
def latex_ticklabels(lbls_x,lbls_y):
return [matplotlib.ticker.FixedFormatter(lbls_x),matplotlib.ticker.FixedFormatter(lbls_y)]
ft=fontsize
return plot([],ticks=[x_ticks,y_ticks],tick_formatter=latex_ticklabels(x_labels,y_labels),fontsize=ft)
PL=plot_labels([1,3],["$x_1$","$x_2$"],[1,2,3.5],["$y_1$","$y_2$","$y_3$"],fontsize=15)
P0=plot(x,(x,0,2))
P1=plot(x^2,(x,0,4))
show(P0+PL)
show(P1+PL)
==========================
I hope this is useful
diff --git a/sage/plot/graphics.py b/sage/plot/graphics.py
--- a/sage/plot/graphics.py
+++ b/sage/plot/graphics.py
@@ -1913,7 +1913,7 @@
raise ValueError('Expand the range of the dependent variable to allow two multiples of your tick locator (option `ticks`).')
x_formatter, y_formatter = tick_formatter
- from matplotlib.ticker import FuncFormatter
+ from matplotlib.ticker import FuncFormatter, FixedFormatter
from sage.misc.latex import latex
from sage.symbolic.ring import SR
if x_formatter is None:
@@ -1924,6 +1924,8 @@
x_formatter = FuncFormatter(lambda n,pos: _multiple_of_constant(n,pos,x_const))
elif x_formatter == "latex":
x_formatter = FuncFormatter(lambda n,pos: '$%s$'%latex(n))
+ elif isinstance(x_formatter, (list, tuple)):
+ x_formatter = FixedFormatter(x_formatter)
if y_formatter is None:
y_formatter = OldScalarFormatter()
elif y_formatter in SR:
@@ -1932,6 +1934,8 @@
y_formatter = FuncFormatter(lambda n,pos: _multiple_of_constant(n,pos,y_const))
elif y_formatter == "latex":
y_formatter = FuncFormatter(lambda n,pos: '$%s$'%latex(n))
+ elif isinstance(y_formatter, (list, tuple)):
+ y_formatter = FixedFormatter(y_formatter)
subplot.xaxis.set_major_locator(x_locator)
subplot.yaxis.set_major_locator(y_locator)
plot(x, (x,0,2), ticks=[[1,2],[1,2,3.5]], tick_formatter=[["$x_1$","$x_2$"],["$y_1$","$y_2$","$y_3$"]])
len(ticks[0]) == len(tick_formatter[0])