比较具有不同刻度的多个图表的趋势

huangapple go评论67阅读模式
英文:

Comparing the trend of several graphs with different scales

问题

如何在一个图中绘制具有不同x和y轴刻度的多个图?例如,我们有以下列表:a=[0, 1, 2, 3]、b=[10, 20, 30, 40, 50]、c=[1000, 2000, 3000, 4000]、aa=[5, 6, 7, 8]、bb=[50, 60, 70, 80, 90]和cc=[5000, 6000, 7000, 8000],我们想要在一个图中绘制(a, aa)、(b, bb)和(c, cc)的散点图。当我们使用plt.scatter(a,aa)、plt.scatter(b,bb)和plt.scatter(c,cc)时,最后一个图的刻度应用于所有图。如何防止这种情况?

for i in range(30):
    plt.scatter(dif_f[i], f_network_data_f[i],  
                label=f'demand{(i*5)+5}')
plt.axhline(0, ls='--', lw=1, color='blue')
plt.axvline(0, ls='--', lw=1, color='blue')
plt.xlabel("$ζ_i$(正值)")
plt.ylabel("$W_{14,i}$")
plt.title("$W_{14,i}$与$ζ_i$" + f"(每个起点-目的地每小时的平均车辆数)", fontsize=9)
plt.legend()
plt.show()
英文:

How can we have multiple plots with different x and y axis scale in one plot?
For example we have the lists a=[0, 1, 2, 3], b=[10, 20, 30, 40, 50], c=[1000, 2000, 3000, 4000], aa=[5, 6, 7, 8], bb=[50, 60, 70, 80, 90] and cc=[5000, 6000, 7000, 8000] and we want to have scatter plots of (a, aa), (b, bb), (c, cc) in a plot. When we use plt.scatter(a,aa), plt.scatter(b,bb) and plt.scatter(c,cc), the scale of last plot is applied to all plots. How can we prevent this?

for i in range(30):
    plt.scatter(dif_f[i], f_network_data_f[i],  
                label=f'demand{(i*5)+5}')
plt.axhline(0, ls='--', lw= 1, color='blue')
plt.axvline(0, ls='--', lw= 1, color='blue')
plt.xlabel("$ζ_i$ (positive values)")
plt.ylabel("$W_{14,i}$")
plt.title("$W_{14,i}$ versus $ζ_i$"+f" (average of cars per hour from each origin-destinatio)", fontsize=9)
plt.legend()
plt.show()

答案1

得分: 1

import matplotlib.pyplot as plt

a = [0, 1, 2, 3]
b = [10, 20, 30, 40, 50]
c = [1000, 2000, 3000, 4000]
aa = [5, 6, 7, 8]
bb = [50, 60, 70, 80, 90]
cc = [5000, 6000, 7000, 8000]

fig, ax1 = plt.subplots()
######################################## 第一个散点图 (a, aa)
ax1.scatter(a, aa, color='blue')
ax1.set_xlabel('散点图')
ax1.set_ylabel('a 和 aa', color='blue')

ax2 = ax1.twinx() # 定义第二组共享相同 x 轴的坐标轴
######################################## 第二个散点图 (b, bb)
ax2.scatter(b, bb, color='red')
ax2.set_ylabel('b 和 bb', color='red')

ax3 = ax1.twiny() # 定义第三组共享相同 x 轴的坐标轴
######################################## 第三个散点图 (c, cc)
ax3.scatter(c, cc, color='green')
ax3.set_xlabel('c 和 cc', color='green')

plt.show()

比较具有不同刻度的多个图表的趋势

英文:

Like this?? Hoping to have understood well...

import matplotlib.pyplot as plt

a = [0, 1, 2, 3]
b = [10, 20, 30, 40, 50]
c = [1000, 2000, 3000, 4000]
aa = [5, 6, 7, 8]
bb = [50, 60, 70, 80, 90]
cc = [5000, 6000, 7000, 8000]

fig, ax1 = plt.subplots()
######################################## First scatter plot (a,aa)
ax1.scatter(a, aa, color='blue')
ax1.set_xlabel('scatter plot')
ax1.set_ylabel('a and aa', color='blue')

ax2 = ax1.twinx() # define a second set of axes that shares the same x-axis
######################################## Second scatter plot (b,bb)
ax2.scatter(b, bb, color='red')
ax2.set_ylabel('b and bb', color='red')

ax3 = ax1.twiny() # define a third set of axes that shares the same x-axis
######################################## Third scatter plot (c,cc)
ax3.scatter(c, cc, color='green')
ax3.set_xlabel('c and cc', color='green')

plt.show()

比较具有不同刻度的多个图表的趋势

huangapple
  • 本文由 发表于 2023年6月8日 14:52:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76429284.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定