Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format y-axis as percent in plot.ly

Tags:

How do I format the y-axis as percent in plot.ly?. in var layout I have the following settings for the y-axis:

   yaxis: {             hoverformat: ",.0%"           }, 

which changes the hover to percentages but the values printed on the y-axis still go from 0-1 instead of 0-100.

Any help is much appreciated.

like image 962
Wessi Avatar asked Feb 04 '17 17:02

Wessi


People also ask

How do I get Y axis percentage in MatPlotLib?

MatPlotLib with PythonCreate a list of numbers as y. Create a number of bins. Plot a histogram using hist() method, where y, bins, and edgecolor are passed in the argument. Store the patches to set the percentage on Y-axis.

How do you change Y axis labels to percentages in R?

Since we need to add percentages in the labels of the Y-axis, the keyword “labels” is used. Now use scales: : percent to convert the y-axis labels into a percentage. This will scale the y-axis data from decimal to percentage. It simply multiplies the value by 100.

How do you flip the Y axis in Plotly?

Reversed Axes You can tell plotly's automatic axis range calculation logic to reverse the direction of an axis by setting the autorange axis property to "reversed" . Here is an example of reversing the direction of the y axes for a faceted scatter plot created using Plotly Express.


1 Answers

In order to change the format of the y-axis you need to set tickformat, not hoverformat.

var trace1 = {    x: [1, 2, 3, 4],    y: [0.10, 0.15, 0.43, 0.17],    type: 'scatter'  };    var trace2 = {    x: [1, 2, 3, 4],    y: [0.16, 0.5, 0.11, 0.9],    type: 'scatter'  };    var layout = {    yaxis: {      tickformat: ',.0%',      range: [0,1]    }  }    var data = [trace1, trace2];  Plotly.newPlot('myDiv', data, layout);
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>  <div id="myDiv" style="width: 480px; height: 400px;">
like image 140
Maximilian Peters Avatar answered Sep 30 '22 20:09

Maximilian Peters