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 ?
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()
© 2024 OneMinuteCode. All rights reserved.