Ask Your Question

Revision history [back]

sage: plt.arrow(1,1,-1,-1,head_width=0.1)

You can try:

sage: plt.arrow(1,1,-1,-1,head_width=0.1)
plt.arrow(1,1,1,-1,color='orange',head_width=.1,head_length=.2)

to see all options, type:

sage: plt.arrow?

You To add an arrow somewhere, you can try:

sage: plt.arrow(1,1,1,-1,color='orange',head_width=.1,head_length=.2)

to see all options, type:

sage: plt.arrow?

To add an arrow on the axes:

To add an arrow somewhere, you can try:

sage: plt.arrow(1,1,1,-1,color='orange',head_width=.1,head_length=.2)

to see all options, type:

sage: plt.arrow?

To add an arrow on along the axes:axes with matplotlib, this is a bit harder since matplotlib understands the Sage plot as an image, hence you should find where to add the axes. Here is a dirty example that try to stick to your framework:

f(x) = cos(x)
from mpl_toolkits.axes_grid.axislines import SubplotZero

import matplotlib.pyplot as plt
plt.clf()
fig = plt.figure()
p = plot(f(x), (0, 2*pi))
# we store the position of the axes of the Sage plot, for a further use in the matplotlib plot.
L = p.get_axes_range()

# Here are the axes
ax = SubplotZero(fig, 111)
fig.add_subplot(ax)
for direction in ["xzero", "yzero"]:
    ax.axis[direction].set_axisline_style("-|>")
    ax.axis[direction].set_visible(True)
for direction in ["left", "right", "bottom", "top"]:
    ax.axis[direction].set_visible(False)

# here we shift the axes according to the Sage plot:
offset = 0.12 # dirty adjustment
ax.set_xlim(L['xmin']-offset,L['xmax'])
ax.set_ylim(L['ymin'],L['ymax'])

p.matplotlib(figure = fig)

fig.savefig('')
plt.close()

To add an arrow somewhere, you can try:

sage: plt.arrow(1,1,1,-1,color='orange',head_width=.1,head_length=.2)

to see all options, type:

sage: plt.arrow?

To add an arrow along the axes with matplotlib, this is a bit harder since matplotlib understands the Sage plot as an image, hence you should find where to add the axes. Here is a dirty example that try to stick to your framework:

f(x) = cos(x)
from mpl_toolkits.axes_grid.axislines import SubplotZero

import matplotlib.pyplot as plt
plt.clf()
fig = plt.figure()
p = plot(f(x), (0, 2*pi))
# we store the position of the axes of the Sage plot, for a further use in the matplotlib plot.
L = p.get_axes_range()

# Here are the axes
ax = SubplotZero(fig, 111)
fig.add_subplot(ax)
for direction in ["xzero", "yzero"]:
    ax.axis[direction].set_axisline_style("-|>")
    ax.axis[direction].set_visible(True)
for direction in ["left", "right", "bottom", "top"]:
    ax.axis[direction].set_visible(False)

# here we shift the axes according to the Sage plot:
offset = 0.12 # dirty adjustment
ax.set_xlim(L['xmin']-offset,L['xmax'])
ax.set_ylim(L['ymin'],L['ymax'])

p.matplotlib(figure = fig)

fig.savefig('')
plt.close()

There should be a better solution.

To add an arrow somewhere, you can try:

sage: plt.arrow(1,1,1,-1,color='orange',head_width=.1,head_length=.2)

to see all options, type:

sage: plt.arrow?

To add an arrow along the axes with matplotlib, this is a bit harder since matplotlib understands the Sage plot as an image, hence you should find where to add the axes. Here is a dirty example that try to stick to your framework:

f(x) = cos(x)
from mpl_toolkits.axes_grid.axislines import SubplotZero

import matplotlib.pyplot as plt
plt.clf()
fig = plt.figure()
p = plot(f(x), (0, 2*pi))
# we store the position of the axes of the Sage plot, for a further use in the matplotlib plot.
L = p.get_axes_range()

# Here are the axes
ax = SubplotZero(fig, 111)
fig.add_subplot(ax)
for direction in ["xzero", "yzero"]:
    ax.axis[direction].set_axisline_style("-|>")
    ax.axis[direction].set_visible(True)
for direction in ["left", "right", "bottom", "top"]:
    ax.axis[direction].set_visible(False)

# here we shift the axes according to the Sage plot:
offset = 0.12 # dirty adjustment
ax.set_xlim(L['xmin']-offset,L['xmax'])
ax.set_ylim(L['ymin'],L['ymax'])

p.matplotlib(figure = fig)

fig.savefig('')
plt.close()

There should be a better solution.

Unfortunately, there seems not to be a solution from Sage's plot yet, see trac ticket 10740.