0

So currently I'm creating a plot which consists of the code:

plt.imshow(prob_mesh[:, 1].reshape((1000, 1000)),
               extent=(-4, 4, -4, 4), origin='lower')
plt.scatter(predicting_classes_pos_inputs[:, 0], predicting_classes_pos_inputs[:, 1], marker='o', c='w',
            edgecolor='k')

Notice that both these two are supposed to be in the the same plot, now I would like to add:

plt.imshow(prob_mesh[:, 0].reshape((1000, 1000)),
           extent=(-4, 4, -4, 4), origin='lower')
plt.scatter(predicting_classes_neg_inputs[:, 0], predicting_classes_neg_inputs[:, 1], marker='o', c='w',
            edgecolor='k')

That is, I want these two be plotted in the same plot, but next to each other, hope you understand, how would one implement something like this?

DavidG
  • 24,279
  • 14
  • 89
  • 82
Jan Erst
  • 89
  • 2
  • 9
  • 1
    Possible duplicate of [How to make two plots side-by-side using Python](https://stackoverflow.com/questions/42818361/how-to-make-two-plots-side-by-side-using-python) – DavidG Jan 10 '19 at 16:24
  • And another possible way - https://stackoverflow.com/questions/31726643/how-do-i-get-multiple-subplots-in-matplotlib – DavidG Jan 10 '19 at 16:25
  • it seems like he's using a predefined function whereas I have two plots which I want in the same plot, and then a yet another one of these plots. I see that they are similiar, but a duplicate ? – Jan Erst Jan 10 '19 at 16:30
  • Keep the first plot the same. For the second plot use `fig,(ax1,ax2) = plt.subplots(1,2)` and then `ax1.imshow(...)` and `ax2.scatter(...)` – DavidG Jan 10 '19 at 16:55
  • @DavidG: I understood it like this. `ax1` will contain both `imshow` and `scatter` for first two plot command (pos_input), Then `ax2` will contains `imshow` and `scatter` for the last two plot commands (neg_inputs) – Sheldore Jan 10 '19 at 16:57
  • @Bazingaa yeah it could be like that, though it's not completely clear. I guess we have to wait for OP to clarify – DavidG Jan 10 '19 at 17:00
  • Based on the output of my answer and looking at positive, negative values and the :0 and :1 indices, I am very much positive that he/she wants something like I said. But yeah, let's wait – Sheldore Jan 10 '19 at 17:00

1 Answers1

2

IIUC, you want something like the following. Below is one working answer for you using some fake data. Just replace it with your actual data and see if it served your need.

import matplotlib.pyplot as plt
import numpy as np

prob_mesh = np.random.randint(-4, 4, (100, 100))

f, (ax1, ax2) = plt.subplots(1, 2)

ax1.imshow(prob_mesh[:, 1].reshape((10, 10)),extent=(-4, 4, -4, 4), origin='lower')
ax1.scatter(prob_mesh[:, 1], prob_mesh[:, 0], marker='o', c='w',edgecolor='k')

ax2.imshow(prob_mesh[:, 1].reshape((10, 10)),extent=(-4, 4, -4, 4), origin='lower')
ax2.scatter(prob_mesh[:, 1], prob_mesh[:, 0], marker='o', c='w',edgecolor='k')

enter image description here

Sheldore
  • 37,862
  • 7
  • 57
  • 71