python - 在 Python 中绘制具有三个变量的图形
问题描述
我试图在同一个图中显示三个变量的可视化。我会更好地解释,这是代码:
import pandas as pd
from matplotlib import pyplot as plt
an_1 = pd.read_csv('an_1.csv', header=None, names=('Pd', 'V')) # M = 10 ^ 3 (gamma=0.01)
# ex for stack: an_1 = pd.DataFrame(data = {'Pd': [0.5,0.6,0.7,0.8], 'V':[200,210,230,240]})
plt.figure(figsize=(8,5), dpi=100)
plt.plot (an_1.Pd, an_1.V, 'r*--', label='Analyt_1')
perc_excedd = pd.read_csv('perc.csv', header=None, names=('Pd', 'V', 'exc'))
# ex for stack: perc_excedd = pd.DataFrame(data = {'Pd': [0.5,0.5,0.5,0.4,0.4,0.4],
#'V':[200,210,220,200,210,220], 'perc':[0.1,0.1,0.2,0.3,0.1,0.2,0.3]})
基本上an1.csv
有不同的值Pd
和一个特定的值V
。在perc.csv
我有一个单一的值Pd
,其中的不同值perc_exceed
对应于不同的值V
。在评论中,我只是放了随机值来帮助说明清楚。
我想拥有我已经拥有的图表,并在其中添加另一个 y 轴,其点perc_exceed
取决于Pd
和 on V
。
希望我已经足够清楚了。谢谢!
解决方案
您可以使用该twiny
功能。
ax1 = plt.gca() # get the current axis
ax2 = ax1.twinx() # get another y axis.
ax1 .plot (an_1.Pd, an_1.V, 'r*--', label='Analyt_1')
ax2 .plot (perc_excedd .Pd, perc_excedd .V, 'g*--', label='Excedd')
推荐阅读
- pytorch - 使用 pytorch 进行线性回归
- objective-c - 在Objective C中过滤,分组和划分2D NSArray
- java - Maven - 始终下载最新版本的依赖项或插件
- java - HashMap 比较不识别整数
- python - 张量的形状为 [?, 0] - 如何重塑为 [?,]
- swift - 使用 Swift 函数,该函数采用通用序列
- javascript - 根据数据库检查日期的事件
- html - 房地产网站项目中的引导问题:列之间没有空间
- android - Android Work Manager - Work Manager 会 100% 确保后台执行完成吗?
- python - 构造函数时的类型检测和碰撞避免