8

I'd like to plot 2 graphs (horizontally), and I'd like one to be a polar graph and the other cartesian. I have the following code which generates 2 cartesian graphs:

x = [1,2,3]
y = [1,2,3]
a = [2,3,4]
b = [5,7,5]

fig, (ax1,ax2) = plt.subplots(ncols = 2)
ax1.scatter(x,y)
ax2.scatter(a,b)
plt.show()

Note these are just random points I chose. How can I specify that I want, say the x-y plot, to be in polar?

ATP
  • 603
  • 1
  • 9
  • 14

1 Answers1

7

There unfortunately is no way to change the projection to polar on an existing axes, but you could do this

import matplotlib.pyplot as plt

x = [1,2,3]
y = [1,2,3]
a = [2,3,4]
b = [5,7,5]

fig = plt.figure()
ax1 = plt.subplot(121)
ax2 = plt.subplot(122, projection='polar')

ax1.scatter(x,y)
ax2.scatter(a,b)
plt.show()
rinkert
  • 6,593
  • 2
  • 12
  • 31
  • What's the difference between using plt.sublot() and plt.subplots()? – ATP Jul 12 '17 at 18:11
  • @Julian `subplots` can create an array of axes objects, where `subplot` only creates one subplot at a time, at the designated position in the grid, on which you can find a detailed explanation [here](https://stackoverflow.com/a/3584933/7054628) – rinkert Jul 12 '17 at 18:15