Python matplotlib中缺少另一种颜色
当我尝试用python绘制以下数据时,我在图形中看不到绿色部分。请在下面找到。同时,请注意,我使用的是python 2.7.4Python matplotlib中缺少另一种颜色,python,matplotlib,Python,Matplotlib,当我尝试用python绘制以下数据时,我在图形中看不到绿色部分。请在下面找到。同时,请注意,我使用的是python 2.7.4 import pandas as pd import numpy as np import matplotlib.pyplot as plt plt.style.use('ggplot') %matplotlib inline range = pd.date_range('2015-01-01', '2015-12-31', freq='15min') df = pd
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('ggplot')
%matplotlib inline
range = pd.date_range('2015-01-01', '2015-12-31', freq='15min')
df = pd.DataFrame(index = range)
df
# Average speed in miles per hour
df['speed'] = np.random.randint(low=0, high=60, size=len(df.index))
# Distance in miles (speed * 0.5 hours)
df['distance'] = df['speed'] * 0.25
# Cumulative distance travelled
df['cumulative_distance'] = df.distance.cumsum()
df.head()
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
ax1.plot(df.index, df['speed'], 'g-')
ax2.plot(df.index, df['distance'], 'b-')
ax1.set_xlabel('Date')
ax1.set_ylabel('Speed', color='g')
ax2.set_ylabel('Distance', color='b')
plt.show()
plt.rcParams['figure.figsize'] = 12,5
速度和距离是两个相互成正比的参数。如果对速度/距离集进行规格化,则会得到完全相同的图形。当您使用alpha=1(不透明)绘制草图时,您看到的唯一颜色是最后绘制的颜色(蓝色)。如果使用alpha 1: 您可以看到绿色(实际上是绿色和蓝色的混合物):
速度和距离是两个相互成正比的参数。如果对速度/距离集进行规格化,则会得到完全相同的图形。当您使用alpha=1(不透明)绘制草图时,您看到的唯一颜色是最后绘制的颜色(蓝色)。如果使用alpha 1: 您可以看到绿色(实际上是绿色和蓝色的混合物):
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
ax1.plot(df.index, df['speed'], 'g-', alpha=0.5)
ax2.plot(df.index, df['distance'], 'b-', alpha=0.1)
ax1.set_xlabel('Date')
ax2.set_ylabel('Distance', color='b')
ax1.set_ylabel('Speed', color='g')
plt.show()
plt.rcParams['figure.figsize'] = 12,5