0

I would like to add a colour scale to this plot. The code below does exactly what I want. This colour scale should indicate a third value which comes from another list.

The Data I want to plot is in one list, the third value is in another and the length of these lists are different. At the moment I select the Data with a list of index (b1). So I have also to do a list of index for my third value (c1).

I thought about using a colourmap to do this, but so far I never worked with colourmaps. And also dindn't found a good explanation in the internet so far. So I hope you could help me.

b1=(35,23,33,8,38,24,40,22,28)
for i in b1:
    plt.plot(x_axis,Data[i][1:21],'-', label=str(Data[i][0]))
    plt.xticks(rotation=270)
    plt.xlabel('Pa')
    plt.ylabel('%')
    plt.yscale('log')
plt.legend()
plt.title("Test")
plt.show()    
rpanai
  • 12,515
  • 2
  • 42
  • 64
  • Hello Bjorn -welcome to SO. Which library is 'plt' coming from here? Could you show us your import statements? – FarmerGedden Mar 26 '20 at 13:38
  • Hello Bjorn -welcome to SO. Do you mind to provide a fulll [mcve](/help/mcve)? – rpanai Mar 26 '20 at 14:57
  • Does this answer your question? [How to generate the lineared color plot (cplot) with z values in colorbar](https://stackoverflow.com/questions/58903874/how-to-generate-the-lineared-color-plot-cplot-with-z-values-in-colorbar) – gboffi Mar 26 '20 at 15:41

1 Answers1

0

This is definitely a job for colormaps, use

import matplotlib.cm as cm
cmap = cm.get_colormap('Some_colormap_name')

to initialize your colormap. You can find the names of colormaps here. From there you have to map the values from your third list to values between 1 and zero, then you can select color when you plot:

b1=(35,23,33,8,38,24,40,22,28)
for i in b1:
    plt.plot(x_axis,Data[i][1:21],'-', label=str(Data[i][0]), color = cmap(value_between_1_and_0))

The thing that might make this difficult is deciding what c1-value you would like to use for the different b1-values, since they have different length

  • Perfect, thanks a lot. This is exactly what I need, especially that the cmap value has to be between 0 and 1. I definitely have to adapt my code. I'm still working to get equal long list, what would make everything more simple if I can work with the same index number. – Björn Bauhofer Mar 27 '20 at 16:09