Top and bottom graphing

Asked 1 years ago, Updated 1 years ago, 308 views

Sorry for the rudimentary question, but using matplotlib
·Put a line graph and a bar graph on the top layer and
·Line graph on the lower level with the same X axis as the upper level
How do I code when I create ?

python matplotlib

2023-02-26 15:22

1 Answers

Here is an example.You will also find Examples—Matplotlib 3.7.0 documentation useful.

import random
import matplotlib.pyplot asplt

x = [*range(10)]
data = [ random.sample(range(30,10) for_in range(3) ]
config,ax=plt.subplots(2,1,sharex=True)

ax[0].plot(x, data[0], color='red', label='Data1')
ax[0].bar(x, data[1], zorder=-1, label='Data2')
ax[1].plot(x, data[2], label='Data3')

ax[0].xaxis.set_tick_params(labelbottom=True)
for a in ax —a.legend()

config.supple('Example')
config.tight_layout()
plt.show()

src=


2023-02-26 17:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.