Plotly contour plot colour scale granularity not matching custom colorscale












0















I am trying to create a contour plot with colours from black at a value of -1 to light grey at 0 to red at a value of 1.



I created a custom colorscale that looks like this, where I specified colours for each increment of 0.1 (20 increments from -1 to 1)



[ # Black -> Light grey
[0, 'rgb(0, 0, 0)'],[0.05, 'rgb(0, 0, 0)'],
[0.05, 'rgb(20, 20, 20)'],[0.1, 'rgb(20, 20, 20)'],
[0.1, 'rgb(40, 40, 40)'],[0.15, 'rgb(40, 40, 40)'],
[0.15, 'rgb(60, 60, 60)'],[0.2, 'rgb(60, 60, 60)'],
...
[0.4, 'rgb(160, 160, 160)'],[0.45, 'rgb(160, 160, 160)'],
[0.45, 'rgb(180, 180, 180)'],[0.5, 'rgb(180, 180, 180)'],
# Ligt Grey -> Red
[0.5, 'rgb(187, 162, 162)'],[0.55, 'rgb(187, 162, 162)'],
[0.55, 'rgb(194, 144, 144)'],[0.6, 'rgb(194, 144, 144)'],
[0.6, 'rgb(201, 126, 126)'],[0.65, 'rgb(201, 126, 126)'],
...
[0.9, 'rgb(243, 18, 18)'],[0.95, 'rgb(243, 18, 18)'],
[0.95, 'rgb(255, 0, 0)'],[1, 'rgb(255, 0, 0)']]


However, when I output the plot, my colorscale has increments of 0.2 and so it seems that not all of the colours I specified are shown.
Here is what I get



enter image description here



This is part of the code to display plot, I am not sure what would be needed to have more information.



data = [go.Contour(z=df.values.tolist(),x=list(df.columns),y=list(df.index),colorscale = colScale,zmin=-1,zmax=1)]
fig = go.Figure(data=data,layout=layout)
py.iplot(fig,contours= contour,filename='contPlot'+column)


I am looking for a way to have more colors displayed. Is there a way to display how many "splits" you want in the colour scale where it will interpolate between colours that have been specified ?
Thanks










share|improve this question



























    0















    I am trying to create a contour plot with colours from black at a value of -1 to light grey at 0 to red at a value of 1.



    I created a custom colorscale that looks like this, where I specified colours for each increment of 0.1 (20 increments from -1 to 1)



    [ # Black -> Light grey
    [0, 'rgb(0, 0, 0)'],[0.05, 'rgb(0, 0, 0)'],
    [0.05, 'rgb(20, 20, 20)'],[0.1, 'rgb(20, 20, 20)'],
    [0.1, 'rgb(40, 40, 40)'],[0.15, 'rgb(40, 40, 40)'],
    [0.15, 'rgb(60, 60, 60)'],[0.2, 'rgb(60, 60, 60)'],
    ...
    [0.4, 'rgb(160, 160, 160)'],[0.45, 'rgb(160, 160, 160)'],
    [0.45, 'rgb(180, 180, 180)'],[0.5, 'rgb(180, 180, 180)'],
    # Ligt Grey -> Red
    [0.5, 'rgb(187, 162, 162)'],[0.55, 'rgb(187, 162, 162)'],
    [0.55, 'rgb(194, 144, 144)'],[0.6, 'rgb(194, 144, 144)'],
    [0.6, 'rgb(201, 126, 126)'],[0.65, 'rgb(201, 126, 126)'],
    ...
    [0.9, 'rgb(243, 18, 18)'],[0.95, 'rgb(243, 18, 18)'],
    [0.95, 'rgb(255, 0, 0)'],[1, 'rgb(255, 0, 0)']]


    However, when I output the plot, my colorscale has increments of 0.2 and so it seems that not all of the colours I specified are shown.
    Here is what I get



    enter image description here



    This is part of the code to display plot, I am not sure what would be needed to have more information.



    data = [go.Contour(z=df.values.tolist(),x=list(df.columns),y=list(df.index),colorscale = colScale,zmin=-1,zmax=1)]
    fig = go.Figure(data=data,layout=layout)
    py.iplot(fig,contours= contour,filename='contPlot'+column)


    I am looking for a way to have more colors displayed. Is there a way to display how many "splits" you want in the colour scale where it will interpolate between colours that have been specified ?
    Thanks










    share|improve this question

























      0












      0








      0








      I am trying to create a contour plot with colours from black at a value of -1 to light grey at 0 to red at a value of 1.



      I created a custom colorscale that looks like this, where I specified colours for each increment of 0.1 (20 increments from -1 to 1)



      [ # Black -> Light grey
      [0, 'rgb(0, 0, 0)'],[0.05, 'rgb(0, 0, 0)'],
      [0.05, 'rgb(20, 20, 20)'],[0.1, 'rgb(20, 20, 20)'],
      [0.1, 'rgb(40, 40, 40)'],[0.15, 'rgb(40, 40, 40)'],
      [0.15, 'rgb(60, 60, 60)'],[0.2, 'rgb(60, 60, 60)'],
      ...
      [0.4, 'rgb(160, 160, 160)'],[0.45, 'rgb(160, 160, 160)'],
      [0.45, 'rgb(180, 180, 180)'],[0.5, 'rgb(180, 180, 180)'],
      # Ligt Grey -> Red
      [0.5, 'rgb(187, 162, 162)'],[0.55, 'rgb(187, 162, 162)'],
      [0.55, 'rgb(194, 144, 144)'],[0.6, 'rgb(194, 144, 144)'],
      [0.6, 'rgb(201, 126, 126)'],[0.65, 'rgb(201, 126, 126)'],
      ...
      [0.9, 'rgb(243, 18, 18)'],[0.95, 'rgb(243, 18, 18)'],
      [0.95, 'rgb(255, 0, 0)'],[1, 'rgb(255, 0, 0)']]


      However, when I output the plot, my colorscale has increments of 0.2 and so it seems that not all of the colours I specified are shown.
      Here is what I get



      enter image description here



      This is part of the code to display plot, I am not sure what would be needed to have more information.



      data = [go.Contour(z=df.values.tolist(),x=list(df.columns),y=list(df.index),colorscale = colScale,zmin=-1,zmax=1)]
      fig = go.Figure(data=data,layout=layout)
      py.iplot(fig,contours= contour,filename='contPlot'+column)


      I am looking for a way to have more colors displayed. Is there a way to display how many "splits" you want in the colour scale where it will interpolate between colours that have been specified ?
      Thanks










      share|improve this question














      I am trying to create a contour plot with colours from black at a value of -1 to light grey at 0 to red at a value of 1.



      I created a custom colorscale that looks like this, where I specified colours for each increment of 0.1 (20 increments from -1 to 1)



      [ # Black -> Light grey
      [0, 'rgb(0, 0, 0)'],[0.05, 'rgb(0, 0, 0)'],
      [0.05, 'rgb(20, 20, 20)'],[0.1, 'rgb(20, 20, 20)'],
      [0.1, 'rgb(40, 40, 40)'],[0.15, 'rgb(40, 40, 40)'],
      [0.15, 'rgb(60, 60, 60)'],[0.2, 'rgb(60, 60, 60)'],
      ...
      [0.4, 'rgb(160, 160, 160)'],[0.45, 'rgb(160, 160, 160)'],
      [0.45, 'rgb(180, 180, 180)'],[0.5, 'rgb(180, 180, 180)'],
      # Ligt Grey -> Red
      [0.5, 'rgb(187, 162, 162)'],[0.55, 'rgb(187, 162, 162)'],
      [0.55, 'rgb(194, 144, 144)'],[0.6, 'rgb(194, 144, 144)'],
      [0.6, 'rgb(201, 126, 126)'],[0.65, 'rgb(201, 126, 126)'],
      ...
      [0.9, 'rgb(243, 18, 18)'],[0.95, 'rgb(243, 18, 18)'],
      [0.95, 'rgb(255, 0, 0)'],[1, 'rgb(255, 0, 0)']]


      However, when I output the plot, my colorscale has increments of 0.2 and so it seems that not all of the colours I specified are shown.
      Here is what I get



      enter image description here



      This is part of the code to display plot, I am not sure what would be needed to have more information.



      data = [go.Contour(z=df.values.tolist(),x=list(df.columns),y=list(df.index),colorscale = colScale,zmin=-1,zmax=1)]
      fig = go.Figure(data=data,layout=layout)
      py.iplot(fig,contours= contour,filename='contPlot'+column)


      I am looking for a way to have more colors displayed. Is there a way to display how many "splits" you want in the colour scale where it will interpolate between colours that have been specified ?
      Thanks







      python plotly






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 '18 at 17:07









      VincFortVincFort

      357113




      357113
























          2 Answers
          2






          active

          oldest

          votes


















          1














          Those are parameters related to the contours attribute:



          go.Contour(
          z=df.values.tolist(),
          x=list(df.columns),
          y=list(df.index),
          colorscale=colScale,
          contours=dict(
          size=0.1,
          start=-1,
          end=1
          )
          )


          also you don't need to graduate the color scale yourself, you should only use the base colors:



          [
          [0, 'rgb(0, 0, 0)'],[0.5, 'rgb(187, 162, 162)'],
          [0.5, 'rgb(187, 162, 162)'],[1, 'rgb(255, 0, 0)']
          ]





          share|improve this answer


























          • Thanks for the second part of your answer, it helped me get better colourscale, however, the size part does not work and does not change the splits in the colourscale. Any idea why this is ?

            – VincFort
            Nov 21 '18 at 17:23











          • Yes, sorry, I forgot to swap the zmin and zmax for start and end in contours. I edited the answer, now it should work.

            – vlizana
            Nov 21 '18 at 19:59



















          1














          I finally used ncontours to change the number of colour in the colour scale.



          data = go.Contour(
          z=df.values.tolist(),
          x=list(df.columns),
          y=list(df.index),
          colorscale = colScale,
          zmin=-1,
          zmax=1,
          ncontours=25)





          share|improve this answer



















          • 1





            Be careful with ncontours, from the docs: "Sets the maximum number of contour levels. The actual number of contours will be chosen automatically to be less than or equal to the value of ncontours." meaning if you don't have enough data that number could be smaller.

            – vlizana
            Nov 21 '18 at 21:46











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398042%2fplotly-contour-plot-colour-scale-granularity-not-matching-custom-colorscale%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Those are parameters related to the contours attribute:



          go.Contour(
          z=df.values.tolist(),
          x=list(df.columns),
          y=list(df.index),
          colorscale=colScale,
          contours=dict(
          size=0.1,
          start=-1,
          end=1
          )
          )


          also you don't need to graduate the color scale yourself, you should only use the base colors:



          [
          [0, 'rgb(0, 0, 0)'],[0.5, 'rgb(187, 162, 162)'],
          [0.5, 'rgb(187, 162, 162)'],[1, 'rgb(255, 0, 0)']
          ]





          share|improve this answer


























          • Thanks for the second part of your answer, it helped me get better colourscale, however, the size part does not work and does not change the splits in the colourscale. Any idea why this is ?

            – VincFort
            Nov 21 '18 at 17:23











          • Yes, sorry, I forgot to swap the zmin and zmax for start and end in contours. I edited the answer, now it should work.

            – vlizana
            Nov 21 '18 at 19:59
















          1














          Those are parameters related to the contours attribute:



          go.Contour(
          z=df.values.tolist(),
          x=list(df.columns),
          y=list(df.index),
          colorscale=colScale,
          contours=dict(
          size=0.1,
          start=-1,
          end=1
          )
          )


          also you don't need to graduate the color scale yourself, you should only use the base colors:



          [
          [0, 'rgb(0, 0, 0)'],[0.5, 'rgb(187, 162, 162)'],
          [0.5, 'rgb(187, 162, 162)'],[1, 'rgb(255, 0, 0)']
          ]





          share|improve this answer


























          • Thanks for the second part of your answer, it helped me get better colourscale, however, the size part does not work and does not change the splits in the colourscale. Any idea why this is ?

            – VincFort
            Nov 21 '18 at 17:23











          • Yes, sorry, I forgot to swap the zmin and zmax for start and end in contours. I edited the answer, now it should work.

            – vlizana
            Nov 21 '18 at 19:59














          1












          1








          1







          Those are parameters related to the contours attribute:



          go.Contour(
          z=df.values.tolist(),
          x=list(df.columns),
          y=list(df.index),
          colorscale=colScale,
          contours=dict(
          size=0.1,
          start=-1,
          end=1
          )
          )


          also you don't need to graduate the color scale yourself, you should only use the base colors:



          [
          [0, 'rgb(0, 0, 0)'],[0.5, 'rgb(187, 162, 162)'],
          [0.5, 'rgb(187, 162, 162)'],[1, 'rgb(255, 0, 0)']
          ]





          share|improve this answer















          Those are parameters related to the contours attribute:



          go.Contour(
          z=df.values.tolist(),
          x=list(df.columns),
          y=list(df.index),
          colorscale=colScale,
          contours=dict(
          size=0.1,
          start=-1,
          end=1
          )
          )


          also you don't need to graduate the color scale yourself, you should only use the base colors:



          [
          [0, 'rgb(0, 0, 0)'],[0.5, 'rgb(187, 162, 162)'],
          [0.5, 'rgb(187, 162, 162)'],[1, 'rgb(255, 0, 0)']
          ]






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 21 '18 at 19:57

























          answered Nov 20 '18 at 23:33









          vlizanavlizana

          638215




          638215













          • Thanks for the second part of your answer, it helped me get better colourscale, however, the size part does not work and does not change the splits in the colourscale. Any idea why this is ?

            – VincFort
            Nov 21 '18 at 17:23











          • Yes, sorry, I forgot to swap the zmin and zmax for start and end in contours. I edited the answer, now it should work.

            – vlizana
            Nov 21 '18 at 19:59



















          • Thanks for the second part of your answer, it helped me get better colourscale, however, the size part does not work and does not change the splits in the colourscale. Any idea why this is ?

            – VincFort
            Nov 21 '18 at 17:23











          • Yes, sorry, I forgot to swap the zmin and zmax for start and end in contours. I edited the answer, now it should work.

            – vlizana
            Nov 21 '18 at 19:59

















          Thanks for the second part of your answer, it helped me get better colourscale, however, the size part does not work and does not change the splits in the colourscale. Any idea why this is ?

          – VincFort
          Nov 21 '18 at 17:23





          Thanks for the second part of your answer, it helped me get better colourscale, however, the size part does not work and does not change the splits in the colourscale. Any idea why this is ?

          – VincFort
          Nov 21 '18 at 17:23













          Yes, sorry, I forgot to swap the zmin and zmax for start and end in contours. I edited the answer, now it should work.

          – vlizana
          Nov 21 '18 at 19:59





          Yes, sorry, I forgot to swap the zmin and zmax for start and end in contours. I edited the answer, now it should work.

          – vlizana
          Nov 21 '18 at 19:59













          1














          I finally used ncontours to change the number of colour in the colour scale.



          data = go.Contour(
          z=df.values.tolist(),
          x=list(df.columns),
          y=list(df.index),
          colorscale = colScale,
          zmin=-1,
          zmax=1,
          ncontours=25)





          share|improve this answer



















          • 1





            Be careful with ncontours, from the docs: "Sets the maximum number of contour levels. The actual number of contours will be chosen automatically to be less than or equal to the value of ncontours." meaning if you don't have enough data that number could be smaller.

            – vlizana
            Nov 21 '18 at 21:46
















          1














          I finally used ncontours to change the number of colour in the colour scale.



          data = go.Contour(
          z=df.values.tolist(),
          x=list(df.columns),
          y=list(df.index),
          colorscale = colScale,
          zmin=-1,
          zmax=1,
          ncontours=25)





          share|improve this answer



















          • 1





            Be careful with ncontours, from the docs: "Sets the maximum number of contour levels. The actual number of contours will be chosen automatically to be less than or equal to the value of ncontours." meaning if you don't have enough data that number could be smaller.

            – vlizana
            Nov 21 '18 at 21:46














          1












          1








          1







          I finally used ncontours to change the number of colour in the colour scale.



          data = go.Contour(
          z=df.values.tolist(),
          x=list(df.columns),
          y=list(df.index),
          colorscale = colScale,
          zmin=-1,
          zmax=1,
          ncontours=25)





          share|improve this answer













          I finally used ncontours to change the number of colour in the colour scale.



          data = go.Contour(
          z=df.values.tolist(),
          x=list(df.columns),
          y=list(df.index),
          colorscale = colScale,
          zmin=-1,
          zmax=1,
          ncontours=25)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 '18 at 17:29









          VincFortVincFort

          357113




          357113








          • 1





            Be careful with ncontours, from the docs: "Sets the maximum number of contour levels. The actual number of contours will be chosen automatically to be less than or equal to the value of ncontours." meaning if you don't have enough data that number could be smaller.

            – vlizana
            Nov 21 '18 at 21:46














          • 1





            Be careful with ncontours, from the docs: "Sets the maximum number of contour levels. The actual number of contours will be chosen automatically to be less than or equal to the value of ncontours." meaning if you don't have enough data that number could be smaller.

            – vlizana
            Nov 21 '18 at 21:46








          1




          1





          Be careful with ncontours, from the docs: "Sets the maximum number of contour levels. The actual number of contours will be chosen automatically to be less than or equal to the value of ncontours." meaning if you don't have enough data that number could be smaller.

          – vlizana
          Nov 21 '18 at 21:46





          Be careful with ncontours, from the docs: "Sets the maximum number of contour levels. The actual number of contours will be chosen automatically to be less than or equal to the value of ncontours." meaning if you don't have enough data that number could be smaller.

          – vlizana
          Nov 21 '18 at 21:46


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398042%2fplotly-contour-plot-colour-scale-granularity-not-matching-custom-colorscale%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

          Alcedinidae

          Origin of the phrase “under your belt”?