0

I'm plotting some scatter plots with matplotlib and need to have the marker colors change based on another series of data that I'm not plotting. So it will be a normal XY plot, but the marker colors change based on an unplotted z-axis, essentially. Anyone know how to do this?

Edit: here's the code I'm using

import matplotlib.pyplot as plt
import pandas as pd

fig = plt.figure(figsize=(7, 7), dpi=150)
ax = plt.subplot()

csv = pd.read_csv('FvmTest.csv', index_col='Id')  
data = csv[['CO2max', 'd13c']] 

bdata = data.loc['b'] 

bx = bdata['CO2max']                               
by = bdata['d13c'] 

plt.plot(bx, by, 'b.', label='bdata')  

plt.suptitle('CO2max vs d13c', fontsize=16)
plt.xlabel('CO2max', fontsize=14)
plt.ylabel('d13c', fontsize=14)

plt.show()
beto5243
  • 3
  • 3

1 Answers1

-1

You're going to want to set c = z and z is whatever you're basing the color on

ax.scatter(x, y, c = z, s = 200, cmap='rainbow')

s is the size of the points, you're going to want to choose a size that is large enough that you can see the colors, and you need to select a colormap.

mauve
  • 2,707
  • 1
  • 20
  • 34