0

Folks, I have vector [2,3,5,8,4,3,2,1] that I am plotting on y axis against range(10) as x axis. I am doing this using matplotlib's stackplot.

import matplotlib.pyplot as plt

y = [1, 3, 4, 5, 6, 7, 8, 6]
x = range(8)

fig, ax = plt.subplots()
ax.stackplot(x, y)

plt.show()

Now I have another vector [8, 9, 0, 0, 0, 0, 1, 4], which is intensity for vector y. I need to use this intensity vector to color code my stackplot so that I can visualize the color spectrum. Intensity is out of 10. How do I do that?

3
  • What do you mean by color code stackplot? The purpose of stackplot is to stack the components of different vectors vertically, see here and here Commented Aug 11, 2017 at 20:16
  • Actually you are correct. Don't need to stack here. But I need something similar where I can see color coding for intensity on a graph. Not sure I need bar chart. May be scatter with area fill in with proper intensity? Commented Aug 11, 2017 at 20:51
  • Given that the question is about a stackplot but OP said in comments that this is not actually desired, the question needs to be either edited to state specifically what is needed (also updated according to How to Ask) or closed. Commented Aug 12, 2017 at 12:48

1 Answer 1

1

I made some bar plot, is this what you want? enter image description here

The corresponding code is as follows

import matplotlib.pyplot as plt                                                    
import numpy as np                                                                 

y = [1, 3, 4, 5, 6, 7, 8, 6]                                                       
x = range(len(y))                                                                  

y2 = np.array([8, 9, 0, 0, 0, 0, 1, 4]) / 10.0                                     

fig, ax = plt.subplots()                                                           
ax.bar(x, y, color=map(str, y2))                                                   

plt.show() 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.