I am trying to create a box plot with plotly python but the graph is not showing. I have missing data in the columns that i am using in the graph. Is plotly handle missing data automatically or do i have to fill the missing values before creating the graphs.
For reference, here is my code for the box - plot
- Using Graph objects
fig = go.Figure()
fig.add_box(x= train['meter'], y= train['meter_reading'])
fig.update_layout(title='Meter Reading By Meter Type',
xaxis_title_text='Types of Meter',
yaxis_title_text='Meter Reading')
fig.show()
- Using plotly xpress
fig = px.box(train, x='meter', y='meter_reading')
fig.show()
can anyone help me with this?
Hi @b_prasad26 welcome to the forum! Yes plotly can handle some kind of missing data, for example None or np.nan
. For example the following examples produce valid plots (the None or np.nan
) are just ignored.
import plotly.express as px
import numpy as np
y = np.random.random(2000)
y[::2] = None
fig = px.box(y=y)
fig.show()
or
import plotly.express as px
import numpy as np
y = np.random.random(2000)
y[::2] = np.nan
fig = px.box(y=y)
fig.show()
What is the format of your missing data? You can use the fillna
method of pandas dataframes to fill with None or np.nan.
1 Like
the format is np.nan but the plot is not showing. I couldnβt able to understand why?
Could you please share here a minimal standalone example? Also, could you take a look at the web developer console to see if there are error messages in Javascript ?
1 Like
This is the plot I am trying to make. I did it using pandas. To create the same plot in plotly I used these codes -
fig = px.box(train, x='meter', y='meter_reading')
fig.show()
No error message is showing, just the cell in notebook run but not plot is displayed.
1 Like
ok, but I donβt have the data so I cannot reproduce the error. Could you please create a minimal dataframe within Python, including missing data, and post here a standalone code (ie one that I can run in my notebook) ? For the error message it would be in the Javascript console, which you open usually in the developer tools of your browser.
ok, give me a few minutes. I tried to run your example code and the plot is showing perfectly. I am trying to do the same with my own data but using only the the y variable this time. The dataframe is quite big, so it is taking some time. I will get back to you soon.
1 Like
ok, this error message I am getting from the javascript console -
Source map error: Error: request failed with status 404
Resource URL: http://35.231.201.188:8888/static/notebook/js/main.min.js?v=fd76f62c63dfcfdb33c73b0d15290316
Source Map URL: main.min.js.map
the link it is suggesting for learning more - https://developer.mozilla.org/en-US/docs/Tools/Debugger/Source_map_errors