Four-axis xy plot

As a rule, I try to understand if matplotlib really has this feature.

I have speed (along the x axis) in mph versus power (along the y axis) in the kW graph, to which I need to add rotations (on the second y axis, to the right ) and another speed (on the second x axis, up at the top parts ) in km / h.

Power in kW correlates with speed in miles per hour, and rotation correlates with power, and the second speed (on the second x axis) is only the first speed times the conversion rate.

So my question is: how can I plot xy in matplotlib with two x and two y-axes?

+6
source share
2 answers

Looking for twinx and twiny ?

import matplotlib.pyplot as plt x = range(1,21) plt.xlabel('1st X') plt.ylabel('1st Y') plt.plot(x,x,'r') # against 1st x, 1st y plt.axis([0,50,0,25]) plt.twinx() plt.ylabel('2nd Y') plt.plot(x,x,'g') # against 1st x, 2nd y plt.axis([0,50,0,20]) plt.twiny() plt.xlabel('2nd X') plt.plot(x,x,'b') # against 2nd x, 2nd y plt.axis([0,10,0,20]) plt.show() 

enter image description here

+7
source

My apologies, I misunderstood.

 import numpy as np import matplotlib.pyplot as plt from matplotlib.axes import Axes rect = 0.1, 0.1, 0.8, 0.8 fig = plt.figure() ax1 = fig.add_axes(rect) t = np.arange(0.01, 10.0, 0.01) ax1.plot(t, np.exp(t), 'b-') # Put your speed/power plot here ax1.set_xlabel('Speed (mph)', color='b') ax1.set_ylabel('Power', color='b') ax2 = fig.add_axes(rect, frameon=False) ax2.yaxis.tick_right() ax2.yaxis.set_label_position('right') ax2.xaxis.tick_top() ax2.xaxis.set_label_position('top') ax2.plot(t, np.sin(2*np.pi*t), 'r-') # Put your speed/rotation plot here ax2.set_xlabel('Speed (kmph)', color='r') ax2.set_ylabel('Rotations', color='r') plt.show() 

enter image description here

+4
source

Source: https://habr.com/ru/post/907643/


All Articles