bqplot | Plotting library for IPython/Jupyter notebooks | Data Visualization library
kandi X-RAY | bqplot Summary
kandi X-RAY | bqplot Summary
bqplot is a 2-D visualization system for Jupyter, based on the constructs of the Grammar of Graphics.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of bqplot
bqplot Key Features
bqplot Examples and Code Snippets
plt2.plot(x_values, y_values, axes_options={
y=dict(tick_format='0.2f')
})
from bqplot import pyplot as plt
from bqplot import LinearScale, Axis, Lines, Figure
from ipywidgets import HTML
import pandas as pd
# ---------------------------
maxy= 3
maxx = 6
heightpx = 520
# ---------------------------
sc_y = Linea
example_fig = Figure(marks=[
fcst_uncertainty,
fcst_line,
], axes=[x_ax_fcst, y_ax_fcst])
from bqplot import DateScale, LinearScale, Axis, Figure, Lines
from ipywidgets import FloatSlider, VBox
import pandas as pd
import numpy as np
slider = FloatSlider(value=1, min = 0, max = 1, step = .01, description = 'Weight A')
slider
$ pip install bqplot
$ jupyter labextension install @jupyter-widgets/jupyterlab-manager
$ jupyter labextension install bqplot
import bqplot
def_tt = Tooltip(fields=['index', 'x', 'y'], formats = ['','.2f'],)
from bqplot import pyplot as plt
from bqplot import Tooltip
from bqplot import Scatter
from ipywidgets import Output
fig = plt.figure(title='My t
from ipywidgets.widgets import Dropdown, Button
from ipywidgets.widgets import Layout, HBox, VBox
import bqplot as bq
import pandas as pd
#make example DF
date_list = ['2020-02-01','2020-02-01','2020-02-01','2020-02-01','2020-02-07','2020
x_data = df_ts.columns.values.tolist()
y_end = df_ts.loc[end_date, :].values.flatten()
y_start = df_ts.loc[start_date, :].values.flatten()
x_sc = OrdinalScale()
y_sc = LinearScale()
ax_x = Axis(label='RIC', scale=x_sc, grid_lines='solid',
def hover_handler(map, hover_event):
out.clear_output()
with out:
print(hover_event)
import bqplot as bqp
import ipywidgets as ipw
from IPython.display import display, clear_output
xSc = bqp.LinearScale()
ySc = bqp.LinearScale()
out = ipw.Output()
def hover_handler(self, content):
ou
Community Discussions
Trending Discussions on bqplot
QUESTION
I created an interactive scatterplot using bqplot
where you are allowed to drag points around (using enable_move=True
).
I don't want the user to drag points above the line y=x. If they do, I want the point to snap back to where it was most recently.
The problem is that I'm not sure how to avoid infinite recursion here.
The scatterplot needs to be aware of when its points are moved in order to check the move and possibly snap back. However, when it begins to snap back, this change (of the point positions) seems to trigger that same callback.
Can anyone tell me the "correct" way to deal with this basic issue?
...ANSWER
Answered 2020-Nov-30 at 12:19You can temporarily disable the observe in the on_point_move function. I've changed the logic a bit too.
QUESTION
I'm trying to plot a time series forecast, surrounded by a shaded uncertainty interval timeseries, and have tooltips work for both the line and the perimeter of the uncertainty.
...ANSWER
Answered 2020-Oct-06 at 12:12You'll kick yourself...reorder the marks in the Figure
call to place the uncertainty first, and the line second. The order of the list functions similarly to zorder
in matplotlib.
QUESTION
I am trying to plot a dynamic portfolio performance that changes as the weights of the portfolio change
Assume a portfolio has 2 components with a 50% weighting each. I want to show a chart of the portfolio with sliders representing the weights of the components. I then want to be able to slide the values of the weights around and have the portfolio chart dynamically update.
I have done this for a portfolio that consists of one weight but cant figure out how to amend for more than 1 weight - maybe I need a different approach.
Example below substitutes a random df with 1 column in place of my portfolio df - process should be the same.
In terms of this example if the df had 2 columns - how can I get it working with 2 sliders controlling each weight ?
from bqplot import DateScale, LinearScale, Axis, Figure, Lines
from ipywidgets import FloatSlider, VBox
import pandas as pd
import numpy as np
slider = FloatSlider(value=1, min = 0, max = 1, step = .01, description = 'Weight A')
df = pd.DataFrame(np.random.randint(0,100,size=(100, 1)), columns=list('A'))
x_sc = LinearScale()
y_sc = LinearScale()
ax_x = Axis(label='Date', scale=x_sc, grid_lines='solid')
ax_y = Axis(label='Price', scale=y_sc, orientation='vertical', grid_lines='solid')
line = Lines(y=df['A'],x=df.index , scales={'x': x_sc, 'y': y_sc}, colors = ['#FF0000'])
line2 = Lines(y=df['A'],x=df.index , scales={'x': x_sc, 'y': y_sc})
fig = Figure(axes=[ax_x, ax_y], marks=[line, line2], title='Price Chart')
def new_chart(value):
...ANSWER
Answered 2020-Jul-31 at 06:04Not sure if I have understood you. Do you mean this?
QUESTION
If I run this code on a jupyter notebook
ANSWER
Answered 2020-Jun-16 at 13:42Hi just type this in a cell and then run it, it should work!
QUESTION
I'm attempting to put together a Jupyter Notebook that allows a user to input a state in a dropdown, which would change the result in the second dropdown to only show cities from that state. Once the city is selected, a button could be pressed to refresh the graph (I realize there's you can use manual with interact, but was unable to get this to function properly) and show the resultant data (covid cases over time). I've had some success making the widgets, but I can't get the data to plot correctly.
This is my first time using widgets in Jupyter and I'm a bit lost what with interact, interactivity, display, and observe (not to mention the deprecated on_trait_change). Here's what I have so far...
...ANSWER
Answered 2020-Apr-21 at 17:24from ipywidgets.widgets import Dropdown, Button
from ipywidgets.widgets import Layout, HBox, VBox
import bqplot as bq
import pandas as pd
#make example DF
date_list = ['2020-02-01','2020-02-01','2020-02-01','2020-02-01','2020-02-07','2020-02-07','2020-02-07','2020-02-07']
state_list = ['CA','NY','CA','NY','CA','NY','CA','NY']
city_list = ['San Fran','NYC','LA','Albany','San Fran','NYC','LA','Albany']
cases_list = [0,10,0,12,2,6,4,8]
df = pd.DataFrame(index=date_list)
df['state'] = state_list
df['city'] = city_list
df['cases'] = cases_list
df.index = pd.to_datetime(df.index)
df.rename_axis("date", axis='index', inplace=True)
#getting unique state list sorted in alphabetical order
state_unique = df['state'].unique()
state_unique.sort()
#make graphical parts - 2 dropdowns and refresh button
state = Dropdown(
options=['All'] + list(state_unique),
value='All', #indicates default starting value
description='State:', #this is the label for the dropdown
layout=Layout(width='200px',
margin = '0px 0px 0px 0px')
)
city = Dropdown(
description='City:',
layout=Layout(width='200px',
margin = '0px 0px 0px 0px')
)
b_refresh = Button(
description='Refresh',
icon='fa-refresh',
button_style='warning',
layout=Layout(width='100px',
margin = '0px 0px 0px 60px')
)
#make graph parts
x = list(df.index.unique())
y = list(df.groupby('date')['cases'].sum())
xs = bq.DateScale()
ys = bq.LinearScale(min=0)
line = bq.Lines(
x=x,
y=y,
scales={'x': xs, 'y': ys}
)
x_ax = bq.Axis(
scale=xs,
label='Dates',
grid_lines='solid',
tick_format='%m-%d',
tick_rotate=-0,
label_location ='middle',
label_offset = "40px"
)
y_ax = bq.Axis(
scale=ys,
orientation='vertical',
tick_format=',d',
label='FillInLater',
grid_lines='solid',
label_offset = "60px"
)
# function that updates 'city' dropdown depending on value in 'state' dropdown
def list_cities(x):
if state.value == 'All':
global y
city.options = ['']
y = list(df.groupby('date')['cases'].sum())
else:
temp = ['All'] + sorted(df.loc[df['state'].eq(state.value),'city'].unique())
city.options = temp
update_city(x)
# function that updates graph's y values depending on value in 'city' dropdown
def update_city(x):
global y
if city.value == 'All':
matching_cities = df.loc[(df['state']==state.value),'cases'].to_frame(name='cases')
y = list(matching_cities.groupby('date')['cases'].sum())
else:
y = list(df.loc[\
(df['city']==city.value)&\
(df['state']==state.value),'cases'])
# update plot function
def set_plot(b):
global y
line.y = [y]
#assign widget actions to functions
state.observe(list_cities, names = 'value') #the names part tells .observe the change name to look for, this is only looking for value changes
city.observe(update_city, names = 'value')
b_refresh.on_click(set_plot)
#display all
fig = bq.Figure(
layout=Layout(width='95%', height='400px', border ='solid 1px gray'),
axes=[x_ax, y_ax],
marks=[line],
fig_margin=dict(top=10, bottom=80, left=80, right=20),
animation_duration=500
)
box = HBox(
children=(state, city, b_refresh),
layout=Layout(margin = '10px 0px 10px 0px')
)
vert_box = VBox(
children=(box, fig),
layout=Layout(border='solid 1px gray', margin = '0 0 0 0')
)
display (vert_box)
QUESTION
Today I've been trying to install the module bqplot and use jupyter lab for the very first time.
However, I've not been able to obtain the desired output when using the basic examples as shown on their website.
The code I'm trying to execute is as following:
...ANSWER
Answered 2020-Apr-09 at 13:55I had the same issue and solved it by installing both the bqplot
labextension and the @jupyter-widgets/jupyterlab-manager
extension:
QUESTION
Is it possible to use Jupyter Widgets in Google Colaboratory?
I followed the instructions here, both with ipyleaflet and bqplot
But I got this error message.
Failed to display Jupyter Widget of type Map.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
Is it possible to use these widgets? Or did I make a mistake somewhere?
...ANSWER
Answered 2017-Dec-07 at 03:29It is not currently possible to use them- currently comms messages are not supported, the WidgetManager code is not loaded into outputframes, and multiple output frames on a page is not a configuration that the WidgetManager works with.
Feel free to open a bug at https://github.com/googlecolab/colabtools/issues
QUESTION
I am having trouble getting my tooltip data to show up in my line chart. Here is some very simple code that reproduces the error. When I hover over the line all that shows up is NaN. Can someone please help me? Thank you!
from bqplot import (Axis, LinearScale, Lines, Figure, Tooltip)
x = [1,2,3,4,5]
y = [1,2,3,4,5]
x_sc = LinearScale()
y_sc = LinearScale()
def_tt = Tooltip(fields=['x', 'y'], formats=['.1f', '.1f'])
line_chart = Lines(x=x, y=y, scales= {'x': x_sc, 'y': y_sc}, line_style='solid',default_colors=['dodgerblue'], tooltip=def_tt)
ax_x = Axis(scale=x_sc)
ax_y = Axis(scale=y_sc, orientation='vertical', tick_format='0.2f')
Figure(marks=[line_chart], axes=[ax_x, ax_y])
...ANSWER
Answered 2019-Dec-24 at 10:16Looks like this is an open issue with bqplot (https://github.com/bloomberg/bqplot/issues/702)
One workaround I found around this was to create a scatter chart (for which the tooltip works in the expected way), and plot this with invisible, fully transparent markers. Then plot your visible line on top.
QUESTION
I am doing a little experiment to debug my project. I am trying to manipulate the hue value on HSV colorspace to see the effect on it when I change it back to RGB.
I have a simple image with whole blue background and a single red circle inside of it. I convert it from RGB to HSV and then change one of the values, and then revert it back to the previous value (please see the code, I can't explain it well by using just words). I was expecting the image to remain the same but to my surprise, when I changed it back from HSV to RGB it gives different image.
...ANSWER
Answered 2019-Nov-22 at 07:28Basically, you just used the wrong ColorConversionCode
for your second conversion. If you use COLOR_BGR2HSV_FULL
for the "forward conversion", you need to use COLOR_HSV2BGR_FULL
for the "backward conversion". You used COLOR_HSV2RGB
, which is indeed wrong in two ways: (1) You convert to RGB instead of BGR, and (2) you don't use the full conversion for the H channel.
QUESTION
Use widget to display snippets from a csv file/dataframe and feed to tooltip attribute of bqplot
I am trying to display certain info (statistics such as age group, income, obesity levels etc.) for each state in the US using bqplot. I am able to plot the US map using examples provided on bqplot github. But the tooltip constructor is using columns names from a json file, which is also used to actually display the map. I do not know how to override that so, I decided to use a widget (ideally a container widget) to hold the data I want to display for each state and use the on_hover() method provided in bqplot.map; In fact, I just modified the code in the link below:
Container as tooltip doesn't show contents
to display info for a particular state
...ANSWER
Answered 2019-Oct-08 at 15:13For Point 2:
In your hover_handler
code, you need to capture the information being passed through to the function, and use it to filter your master dataframe (df
). Try changing your hover_handler
code to the below, and see what info is being passed to the function. Then work out how to use this information to filter your dataframe to just the relevant state.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install bqplot
In order to install a previous bqplot version, you need to know which front-end version (JavaScript) matches with the back-end version (Python). For example, in order to install bqplot 0.11.9, you need the labextension version 0.4.9.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page