更改python子图中的字体大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27474764/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Changing fontsize in python subplots
提问by Scott
I have made a phase plot of a bistable stable, with the nulclines on the main graph and have added a subplot with the trajectories overlaying it. However, no matter what I try, I cannot seem to get the x and y labels to increase in font size to 20.
我制作了一个双稳态的相位图,主图上有核线,并添加了一个子图,轨迹覆盖在它上面。但是,无论我尝试什么,我似乎都无法将 x 和 y 标签的字体大小增加到 20。
Any help would be greatly appreciated.
任何帮助将不胜感激。
Although there are similar questions, the answers to said queries don't seem to apply to this particular problem.
尽管存在类似的问题,但上述查询的答案似乎不适用于此特定问题。
Thanks again!
再次感谢!
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid.axislines import SubplotZero
from matplotlib import pylab
from pylab import linspace
from numpy import meshgrid
from numpy import hypot
a1 = 1.0 #(Rate constant)
g1 = 4.0 # Hill number for cdc2
b1 = 200.0 # Rate Constant
k1 = 30.0 #Michaelis Constant
v =1 #coefficient that reflects the strangth of the influence of Wee1 on Cdc2
a2 = 1.0# Rate Constant
g2 = 4.0 #Hill number for Wee1
b2 = 10.0 # Rate Constant
k2 = 1.0# Michaelis constant
# Function for calculating the phase plot
def Function(u,t=0,mu=.1):
x1 = u[0]
y1 = u[1]
dv = (a2* (1.0 - y1) - (b2 * y1 * x1**g2) /(k2 + (x1**g2))) # Model of Cdc2
dx = (a1* (1.0 - x1) - (b1 * x1 * ((v * y1)**g1)) / (k1 + ((v*y1) **g1))) # Model of Wee1
return (dx,dv)
t = linspace(0,1,1) #Return list from 0 to 1 in 25 intervals
u0 = np.array([1,1]) # Creates array for odeint function
mu = [1,10] #call mu for 2
for m in mu:#Get u (differentiation function )
u = odeint(Function,u0,t,args=(m,))
# ax.plot(u[0:,0],u[0:,1])
x = linspace(0,1,17) #Creates values for x
y = linspace(0,1,18)#Creates values for y to plot
x,y = meshgrid(x,y)# creates a grid of x by y
X,Y = Function([x,y])# Applies funciton to grid
M = (hypot(X,Y))# Get hypotenuse of X by Y
X,Y = X/M, Y/M# Calculate length(strength) of arrows
#Calculate Nulclines-----------------------------------------------------------
Nulclinevalues = np.arange(0, 1+0.001, 0.001)#Calulate values to set nulcineto
NulclineXX = []# set to an array
NulclineYY = []#set to an array
# Following 2 formulas show the calculation fo the nullclines
def calcnulclineyy(xx1):
oa2 = 1.0#RAte constant
og2 = 4.0 #Hill number for Wee1
ob2 = 10.0#Rate constant
ok2 = 1.0#Michaelis constant
YY = (oa2*((xx1)**og2) + ok2) / (oa2*((xx1**og2)+ok2)+(ob2*(xx1**og2)))
return YY
def calcnulclinexx(yy1):
oa1 = 1.0 #Rate constant
og1 = 4.0 # Hill number for cdc2
ob1 = 200.0 #Rate constant
ok1 = 30.0#Michaelis constant
ov = 1##coefficient that reflects the strength of the influence of Wee1 on Cdc2
og2 = 4.0 #Hill number for Wee1
XX = (oa1*(ok1+(ov*yy1)**og2)) / (oa1*(ok1+(ov*yy1)**og1)+ob1*(ov*yy1)**og1)
return XX
for YY in Nulclinevalues:
# print Y
NulclineXX.append(calcnulclinexx(YY))
for XX in Nulclinevalues:
#Print X
NulclineYY.append(calcnulclineyy(XX))
fig = plt.figure(figsize=(6,6)) # 6x6 image
ax = SubplotZero(fig,111,) #Plot arrows over figure
fig.add_subplot(ax) # Plot arrows over figure
# Plot both nulcines on same graph
plt.axis((0,1,0,1))
ax.set_title('v = 1',fontweight="bold", size=20) # Title
ax.set_ylabel('Active Wee1', fontsize = 20.0) # Y label
ax.set_xlabel('Active Cdc2-cyclin B', fontsize = 20) # X label
plt.plot (NulclineXX,Nulclinevalues, label = " Cdc2 nulcline",c = 'r', linewidth = '2')
plt.plot (Nulclinevalues,NulclineYY, label = "Wee1 nulcline",c = '#FF8C00', linewidth = '2')
ax.quiver(x,y,X,Y,M) # plot quiver plot on graph
ax.grid(True) # Show major ticks
ax.legend(handletextpad=0,loc='upper right') # Plot legend
plt.show() # Show plot
采纳答案by Joel
Here are the changes I made to the last bit of your code:
以下是我对您的代码的最后一点所做的更改:
fig = plt.figure(figsize=(6,6)) # 6x6 image
ax = plt.gca() #SubplotZero(fig,111,) #Plot arrows over figure
#fig.add_subplot(ax) # Plot arrows over figure
# Plot both nulcines on same graph
plt.axis((0,1,0,1))
ax.set_title('v = 1',fontweight="bold", size=20) # Title
ax.set_ylabel('Active Wee1', fontsize = 20.0) # Y label
ax.set_xlabel('Active Cdc2-cyclin B', fontsize = 20) # X label
plt.plot (NulclineXX,Nulclinevalues, label = " Cdc2 nulcline",c = 'r')
plt.plot (Nulclinevalues,NulclineYY, label = "Wee1 nulcline",c = '#FF8C00')
ax.quiver(x,y,X,Y,M) # plot quiver plot on graph
ax.grid(True) # Show major ticks
ax.legend(handletextpad=0,loc='upper right') # Plot legend
plt.show() # Show plot
I changed the way you defined ax, and removed the call adding it to the figure. (I also did 2 other changes that you probably don't need - for some reason my installation didn't like the linewidth instructions when I tried to show it, so I took them out - it looks like something wrong with my installation).
我改变了你定义 ax 的方式,并删除了将它添加到图中的调用。(我还做了 2 个您可能不需要的其他更改-出于某种原因,我的安装在尝试显示时不喜欢线宽说明,所以我将它们取出来-看起来我的安装有问题)。
回答by elyase
Just use
只需使用
fig, ax = plt.subplots(figsize=(6,6))
instead of:
代替:
fig = plt.figure(figsize=(6,6)) # 6x6 image
ax = SubplotZero(fig,111,) #Plot arrows over figure
fig.add_subplot(ax) # Plot arrows over figure
BTW nice plot!
BTW 剧情不错!