2011-02-14 6 views
7

'daki bilimsel gösterimde değiştirme İkiz eksenini ve ayrıca bilimsel gösterimi kullanarak bazı eğrileri çiziyorum. Etikete biraz renk koymuştum ama ayar, ekseninin bilimsel gösteriminin güç göstergesini etkilemiyor gibi görünüyor. Herhangi bir hile var mı?Ofsetin rengini matplotlib

fig = pylab.figure() 
ax1 = fig.add_subplot(111) 
ax2 = ax1.twinx() 

# Plotting the data 
plot_ax1, = ax1.plot() 
plot_ax2, = ax2.plot() 

# Setting the label colors 
ax2.yaxis.set_offset_position('right') # To set the power indicator of ax2 
ax1.yaxis.label.set_color(plot_ax1.get_color()) 
ax2.yaxis.label.set_color(plot_ax2.get_color()) 

# Setting the ticker properties  
tkw = dict(size=4, width=1.5) 
ax1.ticklabel_format(style='sci', scilimits=(0,0), axis='y') 
ax2.ticklabel_format(style='sci', scilimits=(0,0), axis='y')   
ax1.tick_params(axis='y', colors=plot_ax1.get_color(), **tkw) 
ax2.tick_params(axis='y', colors=plot_ax2.get_color(), **tkw) 
ax1.tick_params(axis='x', **tkw) 

# Setting the legend 
lines = [plot_ax1, plot_ax2] 
ax1.legend(lines, [l.get_label() for l in lines],'upper left') 
+0

Matplotlib posta listesine bakabilirsiniz. http://sourceforge.net/mailarchive/forum.php?forum_name=matplotlib-users –

+0

Biliyorum tick_params son zamanlarda matplotlib'e eklendi: http://matplotlib.sourceforge.net/users/whats_new.html#tick-params It 'renkler' hem kene renklerini değiştirmeli hem de etiket renklerini işaretlemeli gibi görünüyor, ancak öyle değil. 'Labelcolor' seçeneğini açıkça belirlediniz mi? – Andrew

cevap

10

O tick_params zaten bu yapmaz muhtemelen sadece bir gözetim, ama sadece manuel olarak ayarlayabilirsiniz:

Example

İşte benim kodudur.

Örneğin, sadece örnek kod Bu iki satırı ekleyin:

ax1.yaxis.get_offset_text().set_color(plot_ax1.get_color()) 
ax2.yaxis.get_offset_text().set_color(plot_ax2.get_color()) 

Daha kapsamlı bir örnek olarak, kod yukarıdaki pasajı ve bazı rasgele verileri kullanarak:

import matplotlib.pyplot as plt 
import numpy as np 

numdata = 100 
t = np.linspace(0.05, 0.11, numdata) 
x1 = np.cumsum(np.random.random(numdata) - 0.5) * 40000 
x2 = np.cumsum(np.random.random(numdata) - 0.5) * 0.002 

fig = plt.figure() 
ax1 = fig.add_subplot(111) 
ax2 = ax1.twinx() 

# Plotting the data 
plot_ax1, = ax1.plot(t, x1, 'r-', label='x1') 
plot_ax2, = ax2.plot(t, x2, 'g-', label='x2') 

# Setting the label colors 
ax2.yaxis.set_offset_position('right') # To set the power indicator of ax2 
ax1.yaxis.label.set_color(plot_ax1.get_color()) 
ax2.yaxis.label.set_color(plot_ax2.get_color()) 

# Setting the ticker properties  
tkw = dict(size=4, width=1.5) 
ax1.ticklabel_format(style='sci', scilimits=(0,0), axis='y') 
ax2.ticklabel_format(style='sci', scilimits=(0,0), axis='y')   
ax1.tick_params(axis='y', colors=plot_ax1.get_color(), **tkw) 
ax2.tick_params(axis='y', colors=plot_ax2.get_color(), **tkw) 

ax1.yaxis.get_offset_text().set_color(plot_ax1.get_color()) 
ax2.yaxis.get_offset_text().set_color(plot_ax2.get_color()) 

ax1.tick_params(axis='x', **tkw) 

# Setting the legend 
lines = [plot_ax1, plot_ax2] 
ax1.legend(lines, [l.get_label() for l in lines],'upper left') 

plt.show() 

enter image description here

+0

Cevabınız için çok teşekkür ederim. Sadece iyi çalışıyor ... – TazgerO