不管其价值如何,你甚至在没有<<<><>>>>条码>的情况下,就在我的系统中打上了记号。 作为参考,这里有一个独立的例子,试图基本上遵循你所表述的内容:
import matplotlib.pyplot as plt
import numpy as np
# Generate some data
num = 200
x = np.linspace(501, 1200, num)
yellow_data, green_data = np.random.random((2,num))
green_data -= np.linspace(0, 3, yellow_data.size)
# Plot the yellow data
plt.fill_between(x, yellow_data, 0, color= yellow )
plt.yticks([0.0, 0.5, 1.0], color= yellow )
# Plot the green data
ax2 = plt.twinx()
ax2.plot(x, green_data, g- )
plt.yticks([-4, -3, -2, -1, 0, 1], color= green )
plt.show()
我的猜测是,你的问题主要来自对不同物体的混淆。 我猜测,你的代码比较复杂,当你打电话<编码>plt.yrites时,ax2
不是目前的轴心。 您可在打电话<条码>(<>yps>>之前,明确打上<>sca(ax2)(目前轴向ax2
),并看到这一改动。
Generally speaking, it s best to stick to either entirely the matlab-ish state machine interface or the OO interface, and don t mix them too much. (Personally, I prefer just sticking to the OO interface. Use pyplot
to set up figure objects and for show
, and use the axes methods otherwise. To each his own, though.)
At any rate, with matplotlib >= 1.0, the tick_params
function makes this a bit more convenient. (I m also using plt.subplots
here, which is only in >= 1.0, as well.)
import matplotlib.pyplot as plt
import numpy as np
# Generate some data
yellow_data, green_data = np.random.random((2,2000))
yellow_data += np.linspace(0, 3, yellow_data.size)
green_data -= np.linspace(0, 3, yellow_data.size)
# Plot the data
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
ax1.plot(yellow_data, y- )
ax2.plot(green_data, g- )
# Change the axis colors...
ax1.tick_params(axis= y , labelcolor= yellow )
ax2.tick_params(axis= y , labelcolor= green )
plt.show()
The equivalent code for older versions of matplotlib would look more like this:
import matplotlib.pyplot as plt
import numpy as np
# Generate some data
yellow_data, green_data = np.random.random((2,2000))
yellow_data += np.linspace(0, 3, yellow_data.size)
green_data -= np.linspace(0, 3, yellow_data.size)
# Plot the data
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
ax2 = ax1.twinx()
ax1.plot(yellow_data, y- )
ax2.plot(green_data, g- )
# Change the axis colors...
for ax, color in zip([ax1, ax2], [ yellow , green ]):
for label in ax.yaxis.get_ticklabels():
label.set_color(color)
plt.show()