sys-bio / tellurium

Python Environment for Modeling and Simulating Biological Systems
http://tellurium.analogmachine.org/
Apache License 2.0
107 stars 36 forks source link

Setting xlabel doesn't work #113

Closed hsauro closed 8 years ago

hsauro commented 8 years ago

Setting the xlabel for a graph doesn't work because it doesn't override the current label.

Eg if time is the x axis, the label is 'time'. Typing

plt.xlabel ('Time')

is ignored. This used to work. ylabel works ok.

Update: I noticed that r.plot(xlabel='Time') does work, however I need plt.xlabel ('Time') to work for legacy code.

matthiaskoenig commented 8 years ago

Cannot reproduce.

r.plot(s, xlabel='time')
plt.xlabel("Time")

works fine for me. Make sure to always execute the two lines together (first executing r.plot, than executing the plt.xlabel won't work because the plot is already rendered)

kirichoi commented 8 years ago

I think it is better to leave the default behavior of plot() function to NOT set xlabel automatically from the list of selection names. The proposed solution does not work because plt.xlabel("Time") will create a new empty plot but not replace the xlabel on the original plot.

kirichoi commented 8 years ago

Solve this problem by setting show=False:

import tellurium as te
import matplotlib.pyplot as plt

r = te.loada ('''
$Xo -> S1; k1*Xo;
S1 -> $X1; k2*S1;
k1 = 0.5; k2 = 0.1; Xo = 1; S1 = 0.5;
''')

m = r.simulate (0, 50, 100, ["time", "S1"])
n = r.simulate(0, 10, 100)

r.plot(result=m, show=False)
plt.xlabel("x")
plt.show()

r.plot(result=n)

Be sure to put plt.show() after changing figure element if plotting multiple figures.

0u812 commented 8 years ago

FWIW in recent (conda) versions of roadrunner you can use r.showPlot(). This obviates the pyplot import.

On 03/28/2016 04:55 PM, Kiri Choi wrote:

Solve this problem by setting |show=False|:

|import tellurium as te import matplotlib.pyplot as plt r = te.loada (''' $Xo -> S1; k1_Xo; S1 -> $X1; k2_S1; k1 = 0.5; k2 = 0.1; Xo = 1; S1 = 0.5; ''') m = r.simulate (0, 50, 100, ["time", "S1"]) n = r.simulate(0, 10, 100) r.plot(result=m, show=False) plt.xlabel("x") plt.show() r.plot(result=n) |

Be sure to put |plt.show()| after changing figure element if plotting multiple figures.

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/sys-bio/tellurium/issues/113#issuecomment-202631940