简体   繁体   中英

Plotting a graph in Python with three variables

I am trying to have in the same plot the visualization of three variables. I will explain better, this is the code:

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]})

Basically an1.csv has different values of Pd and a specific value of V . In perc.csv I have for a single value of Pd , different values of perc_exceed which corresponds to different values of V . In the comments I just put random values to help make it clear.

I would like to have the graph I already have and add to it another y axis with the the points of perc_exceed that depends either on Pd and on V .

Hope I've been clear enough. Thanks!

You can use the twiny function.

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM