Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plotly js remove title and title area

How does on remove the title from a plotly js chart?

Example chart I have is as follows

<head>
     <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<div id="myDiv" style="width: 800px; height: 400px;"></div>
<script>

var trace1 = {
   x: [1, 2, 3, 4],
   y: [10, 15, 13, 17],
   mode: 'markers'
};

var trace2 = {
  x: [2, 3, 4, 5],
  y: [16, 5, 11, 9],
  mode: 'lines'
};

var trace3 = {
  x: [1, 2, 3, 4],
  y: [12, 9, 15, 12],
  mode: 'lines+markers'
};

var data = [ trace1, trace2, trace3 ];

var layout = {
  title:false
};

Plotly.newPlot('myDiv', data, layout);
</script>

This chart will have a title "false", I have also tried var layout = { showtitle:false }

setting the title to null: title:'' or simply removing the title line, doesn't display a title, but the title area which is approxiamtely 50px in height above the chart reserved for the title remains, how do I remove this title area?

like image 403
JimmyBanks Avatar asked Jul 16 '16 00:07

JimmyBanks


People also ask

How do I hide my Plotly logo?

Plotly. newPlot('myDiv', data, layout, {displaylogo: false});

How do I hide Plotly toolbar?

Just add displayModeBar: false to the config object and it will disable the floating toolbar in Plotly.

How do you turn off zoom in Plotly?

To disable zoom and panning you need to set: layout. xaxis. fixedrange = true and layout.

How do you change your title color in Plotly?

@alexpetit12 You can set the font color for the entire title not only for substrings of it. layout=go. layout(title = dict(text ='Your title', font =dict(family='Sherif', size=14, color = 'red')), ... ) for more title attributes see https://plot.ly/python/reference/#layout-title.


1 Answers

By removing the title from the layout config it will no longer render it. However, the margins are still configured to create the space for it. You will need to override those default margins as explained here.

I have created a jsFiddle showing that config applied to generate the desired output.

This is the meat of it:

var layout = {
  margin: {
    l: 50,
    r: 50,
    b: 50,
    t: 50,
    pad: 4
  }
};
like image 136
Matt Avatar answered Sep 30 '22 19:09

Matt