Ask Your Question
0

How do I adjust the position of my figure's title and remove the extra set of coordinates shown?

asked 2015-05-12 22:42:54 +0100

Fusion809 gravatar image

updated 2015-05-12 22:57:39 +0100

I tried to solve this problem myself (http://ask.sagemath.org/question/2680...) using this code (which itself is largely copied from http://ask.sagemath.org/answers/15011...):

from sage.calculus.desolvers import desolve_odeint
y,dy = var('y,dy');
g    = 9.8; 
l    = 1; 
f    = [dy,-g/l*cos(y)];
v    = [y,dy];
t    = srange(0,5,0.01);
ci   = [0,0];
sol  = desolve_odeint(f,ci,t,v,rtol=1e-15, atol=1e-10,h0=1e-4,hmax=1e-2,hmin=1e-6,mxstep=10000)
p    = line(zip(t,sol[:,0]));
p2   = line(zip(t,sol[:,1]));

import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid.axislines import SubplotZero

def mplot(sage_plot, equal_scale = False, edit_res = False):
    """
    This function convert sage_plot, created at sage, in matplotlib graph.
    """
    plt.clf()
    fig = plt.figure()
    plt.xlabel(r"$t$")
    plt.ylabel(r"$\theta$")
    plt.title(r"$\frac{d^{2}\theta}{dt^2} = -\frac{g}{l} \cos{\theta}$")
    ax = SubplotZero(fig, 111)
    fig.add_subplot(ax)
    L = sage_plot.matplotlib().gca().lines
    for t in L:
        data = t.get_data()
        ax.add_line(mpl.lines.Line2D(data[0], data[1]))
        ax.autoscale_view()
    if equal_scale:
        ax.axis('equal')
    for direction in ["xzero", "yzero"]:
        ax.axis[direction].set_axisline_style("-|>", size = 2)
        ax.axis[direction].set_visible(True)
    for direction in ["left", "right", "bottom", "top"]:
        ax.axis[direction].set_visible(False)
    ax.axis["yzero"].set_axis_direction("right")
    ax.minorticks_on()    
    ax.grid()
    if edit_res:
        return(fig)
    else:
        plt.savefig('')
        plt.close()

mplot(p,equal_scale = True)

but it gives this output: image description.

My problem with this plot is that the title (i.e., the differential equation) is partially cut off and for some reason there's two alternate numbering schemes along the x and axis (two set from 0 to 1, the others being the real x & y coordinates which go from -pi to 0)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-05-26 11:05:05 +0100

plt.title('Scatter plot pythonspot.com', y=-0.01)

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-05-12 22:42:54 +0100

Seen: 7,053 times

Last updated: May 12 '15