-1

Using plt.figure() , can we get Multiple plots horizontally. Below gives vertical, and tried using plt.figure(nrows=1, ncols=2), and No such Syntax was legal.

fig = plt.figure() #nrows=1, ncols=2)
ax = fig.add_subplot(111)
plt.scatter(x=res['actual'],y=res[0])
fig = plt.figure()
ax = fig.add_subplot(111)
plt.scatter(x=res['actual'],y=res[0])
res['diff']=res['actual']-res[0]
#plt.hist(res['diff'])

res['diff']=res['actual']-res[0]
plt.hist(res['diff'])

fig = plt.figure()
ax = fig.add_subplot(111)
plt.boxplot(res['diff'], showmeans=True)

`fig = plt.figure() #nrows=1, ncols=2)
ax = fig.add_subplot(111)
plt.scatter(x=res['actual'],y=res[0])
fig = plt.figure()
ax = fig.add_subplot(111)
plt.scatter(x=res['actual'],y=res[0])
res['diff']=res['actual']-res[0]
#plt.hist(res['diff'])

res['diff']=res['actual']-res[0]
plt.hist(res['diff'])

fig = plt.figure()
ax = fig.add_subplot(111)
plt.boxplot(res['diff'], showmeans=True)
user2458922
  • 1,691
  • 1
  • 17
  • 37

1 Answers1

1

Your add_subplot(row, col, index) are incorrect.

As your provided code is not replicable such as it contains res['...']. I'll give an intuitive and generalized example for you to follow along.

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(-1, 1, 0.1)
y = np.exp(x)

fig = plt.figure()
ax1 = fig.add_subplot(131) # specify as ax1
ax1.plot(x, y, c='red')
fig.add_subplot(1,3,2)
plt.plot(x, y) # without specify ax
fig.add_subplot(1,3,3)
plt.plot(x, y, ':')

plt.show()

For quick plot, I prefer this due to readability.

plt.subplots(1,3)
plt.subplot(131); plt.plot(x, y, c='red')
plt.subplot(132); plt.plot(x, y)
plt.subplot(133); plt.plot(x, y, ':')
plt.show()

Both are giving the same results.

brixk
  • 36
  • 4