Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

subplot with plotly with multiple traces

i am trying to create subplots for the following plots:

enter image description here

enter image description here

the code i used for the the plots are :

radius_mean1 = df[df['diagnosis']==1]['radius_mean']
radius_mean0 = df[df['diagnosis']==0]['radius_mean']

trace_rm1 = go.Histogram(x = radius_mean1, opacity = 0.75, name = 'malignant')
trace_rm2 = go.Histogram(x = radius_mean0, opacity = 0.75, name = 'benign')

data2 = [trace_rm1,trace_rm2]
layout2 = go.Layout(barmode = 'overlay', title = 'radius mean')
fig2 = go.Figure(data=data2, layout=layout2)

py.iplot(fig2)

and similar for the other plot

now i use the following code i found to create subplots:

fig.append_trace(fig1['data'][1], 1, 1)
fig.append_trace(fig2['data'][0], 2, 1)
py.iplot(fig)

and i get this : enter image description here

how do i add both benign and malignant results to the subplots ? i cant seem to edit the [0] or [ 1] to show both ie have the first 2 plots exactly into my subplot showing both malignant and benign and not just one or the other.

like image 211
Aasheet Kumar Avatar asked Oct 15 '17 00:10

Aasheet Kumar


People also ask

How do you use subplots in Plotly?

Simple SubplotFigures with subplots are created using the make_subplots function from the plotly. subplots module. Here is an example of creating a figure that includes two scatter traces which are side-by-side since there are 2 columns and 1 row in the subplot layout.

How many data points can Plotly handle?

Due to browser limitations, the Plotly SVG drawing functions have a hard time graphing more than 500k data points for line charts, or 40k points for other types of charts. Here are some suggestions: (1) Use the `plotly. graph_objs. Scattergl` trace object to generate a WebGl graph.

What are traces in Plotly?

A plotly. graph_objects. Image trace is a graph object in the figure's data list with any of the named arguments or attributes listed below. Display an image, i.e. data on a 2D regular raster. By default, when an image is displayed in a subplot, its y axis will be reversed (ie.


1 Answers

The data here is not complete, so I using some demo data to present.

import numpy as np
import plotly.graph_objs as go
import plotly

a = np.random.normal(0,1,100)
b = np.random.normal(-2,5,100)

c = np.random.normal(0,1,100)
d = np.random.normal(-2,5,100)

fig = plotly.tools.make_subplots(rows=2,cols=1)

trace_rm1 = go.Histogram(x = a, opacity = 0.75, name = 'malignant')
trace_rm2 = go.Histogram(x = b, opacity = 0.75, name = 'benign')
fig.append_trace(go.Histogram(x = a, opacity = 0.75, name = 'benign'),1,1)
fig.append_trace(go.Histogram(x = b, opacity = 0.75, name = 'malignant'),1,1)
fig.append_trace(go.Histogram(x = c, opacity = 0.75, name = 'benign'),2,1)
fig.append_trace(go.Histogram(x = d, opacity = 0.75, name = 'malignant'),2,1)
fig.layout.update(go.Layout(barmode = 'overlay',))

plotly.offline.plot(fig)

result

like image 77
tianhua liao Avatar answered Sep 29 '22 01:09

tianhua liao