这是为了澄清问题标题。假设您有四个整数列表,您想用它们生成散点图:
a=[3,7,2,8,12,17]
b=[9,4,11,7,6,3]
c=[9,3,17,13,10,5]
d=[5,1,1,14,5,8]
为了简单起见,你还有一个函数f(x)=1/x
,这适用于所有列表,因此:
from __future__ import division
a1=[1/i for i in a]
b1=[1/i for i in b]
c1=[1/i for i in c]
d1=[1/i for i in d]
我的问题:如何添加第二个 y 轴,已知函数返回的值范围为0.06
to 1.0
, 不使用散点图中的任何 a1、b1、c1、d1 列表?
我的意思是:如果您以传统方式生成以下散点图,那么如何根据 a1、b1、c1、d1 的值添加第二个 y 轴,而无需在绘图本身中使用它们的任何系列?
import matplotlib.pyplot as plt
plt.scatter(a,b,c='red',label='reds')
plt.scatter(c,d,c='blue',label='blues')
plt.legend(loc='best')
This is the scatter without the second y axis:
And this is a made up version of the same one, including the second y axis discussed so far:
NB:这个问题不同于this https://stackoverflow.com/questions/7733693/matplotlib-overlay-plots-with-different-scales,因为我不想用不同的比例来绘制。我只想添加具有相关值的第二个轴。