去年我在一个班级中使用了 D3js v3,想将我的代码更新到 v4,但发现 v4 与 v3 不向后兼容,对于已经可以工作的图表,重构代码需要做太多工作。现在我想开始阅读《Web 交互式数据可视化(第 2 版)》一书,但该书于 2017 年使用 V4 出版。我已经阅读了GitHub 上的CHANGES.md文件,听起来 V5(在大多数情况下)向后兼容 V4,只有一些小的更改。
在我开始使用这本新书之前,我想从使用 D3js 的人那里获得有关 V4 和 V5 更改的更多信息。我也很好奇是否建议我使用最新版本的 D3js(V5.6.0),或者使用书籍版本(V4.5.0)?
让我们认为我在数据集中有四个特征,并且每次使用两个特征绘制散点图。我想分别为每个图提供标签。
fig,axes=plt.subplots(ncols=2,figsize=(10,8))
axes[0].scatter(x1,x2],marker="o",color="r")
axes[1].scatter(x3,x4,marker="x",color="k")
axes[0].set(xlabel="Exam score-1",ylabel="Exam score-2")
axes[1].set(xlabel="Exam score-1",ylabel="Exam score-2")
axes[0].set_label("Admitted")
axes[1].set_label("Not-Admitted")
axes.legend()
plt.show()
Run Code Online (Sandbox Code Playgroud)

在这里,我将得到两个散点图,但未显示标签。我想看到第一个图被承认为标签 ,第二个散点图不被承认。
我可以通过使用plt.legend()但无法获取已创建的图来提供标签。
我正在开发散景中的地理仪表板。在散景中使用悬停工具提示相当容易,但是当我悬停在一个字段上时我想填充一个 div。
Python 版本:3.5.2
散景版本:0.13.0
1. 这是仪表板的主视图。

2. 所需输出

我想添加两个交互,
3. 数据:

4. 代码:
from bokeh.io import show, output_notebook, output_file
from bokeh.models import (
GeoJSONDataSource,
HoverTool,
LinearColorMapper,
ColorBar,
BasicTicker,
PrintfTickFormatter,
LogColorMapper,
Range1d,
Plot,
Text
)
from bokeh.plotting import figure
import geopandas as gpd
with open('/home/drogon/Desktop/Rescue-1122-project/punjab_districts(area_pop_den).geojson', 'r') as f:
geo_source = GeoJSONDataSource(geojson=f.read())
df = gpd.read_file('/home/drogon/Desktop/Rescue-1122-project/punjab_districts(area_pop_den).geojson')
print(df.density)
density = df['density']
colors = ['#000003', '#3B0F6F', '#8C2980', '#DD4968', '#FD9F6C']
colors.reverse()
color_mapper = LogColorMapper(palette=colors, low=density.min(), high=density.max())
TOOLS = "pan,wheel_zoom,box_zoom,reset,hover,save"
p = figure(title="Punjab Districts", …Run Code Online (Sandbox Code Playgroud) 嗨,我想得到这种条形图。问题是如何通过选择设置相应的xlables?
我编码如下以删除不需要的国家/地区标签,但图表也有 nan 作为标签。
countries=['United States','Mexico','Japan','China','Korea,Rep.','Ireland','France','Italy']
new_index=list(df.index)
for i in range(len(new_index)):
if new_index[i] not in countries :
new_index[i]=np.nan
Run Code Online (Sandbox Code Playgroud)
对于数据:
import numpy as np
import pandas as pd
#Overall Country list
Countries=['United States','Mexico','Japan','China','Korea,Rep.','Ireland','France','Italy','Czech Republic',
'Austria',
'Slovak Republic',
'Slovenia',
'Germany',
'Portugal',
'Hungary',
'Colombia',
'New Zealand',
'Norway',
'Latvia']
#Countries to highlight
Desired=['United States','Mexico','Japan','China','Korea,Rep.','Ireland','France','Italy']
np.random.seed(0)
Value=np.random.rand(len(Countries))
df = pd.DataFrame({'Countries': Countries,'Value': Value,})
df.sort_values(['Value'],inplace=True)
df.set_index('Countries',drop=True,inplace=True)
ax_1 = df['Value'].plot(kind='bar', title ="graph", figsize=(10, 6), fontsize=12)
ax_1.set_xlabel("Country Name", fontsize=12)
plt.show()
Run Code Online (Sandbox Code Playgroud) 我策划了catplot在seaborn这样的
import seaborn as sns
import pandas as pd
data = {'year': [2016, 2013, 2014, 2015, 2016, 2013, 2014, 2015, 2016, 2013, 2014, 2015, 2016, 2013, 2014, 2015, 2016, 2013, 2014, 2015], 'geo_name': ['Michigan', 'Michigan', 'Michigan', 'Michigan', 'Washtenaw County, MI', 'Washtenaw County, MI', 'Washtenaw County, MI', 'Washtenaw County, MI', 'Ann Arbor, MI', 'Ann Arbor, MI', 'Ann Arbor, MI', 'Ann Arbor, MI', 'Philadelphia, PA', 'Philadelphia, PA', 'Philadelphia, PA', 'Philadelphia, PA', 'Ann Arbor, MI Metro Area', 'Ann Arbor, …Run Code Online (Sandbox Code Playgroud) 我们有项目,分配给不同的团队。现在我必须创建项目时间表。
出于这个问题的目的,我在 jsfiddle.net 中创建了一个虚拟对象。 https://jsfiddle.net/cezar77/6u1waqso/2
“虚拟”数据如下所示:
const projects = [
{
'name': 'foo',
'team': 'operations',
'start_date': '2018-01-01',
'end_date': '2019-12-31'
},
{
'name': 'bar',
'team': 'operations',
'start_date': '2017-01-01',
'end_date': '2018-12-31'
},
{
'name': 'abc',
'team': 'operations',
'start_date': '2018-01-01',
'end_date': '2018-08-31'
},
{
'name': 'xyz',
'team': 'devops',
'start_date': '2018-04-01',
'end_date': '2020-12-31'
},
{
'name': 'wtf',
'team': 'devops',
'start_date': '2018-01-01',
'end_date': '2019-09-30'
},
{
'name': 'qwerty',
'team': 'frontend',
'start_date': '2017-01-01',
'end_date': '2019-01-31'
},
{
'name': 'azerty',
'team': 'marketing',
'start_date': '2016-01-01',
'end_date': '2019-08-31'
}, …Run Code Online (Sandbox Code Playgroud) 巧都,
我正在与情节合作。
我需要画一条曲线并填充它下面的区域。可能会出现一些 NaN,在这种情况下不填充区域非常重要。
请注意,在我的情况下,0 和 NaN 是不同的,因此将 NaN 设置为 0 是解决不适合我的情况的区域问题的方法。
我尝试使用以下代码:
import plotly.graph_objs as go
from plotly.offline import plot
p = go.Scatter(x=range(0,12),
y = [1,2,3,np.nan, np.nan, np.nan, np.nan, np.nan, 0,0,0,5],
fill='tozeroy')
fig = go.Figure([p])
plot(fig, auto_open=True)
Run Code Online (Sandbox Code Playgroud)
但我得到了一个我不喜欢的结果。如您所见,没有与 NaN 对应的点,因此在悬停模式中不会显示任何内容(我喜欢它!)但有区域。
我想达到这个结果:
import plotly.graph_objs as go
from plotly.offline import plot
p1 = go.Scatter(x=range(0,3),
y = [1,2,3],
fill='tozeroy')
p2 = go.Scatter(x=range(8,12),
y = [0,0,0,5],
fill='tozeroy')
fig = go.Figure([p1, p2])
plot(fig, auto_open=True)
Run Code Online (Sandbox Code Playgroud)
(当然,我希望情节只有一种颜色,图例中只有一种元素。)
你能帮我在不将曲线分成多条曲线的情况下重现第二个图吗?
谢谢
是
我正在使用泰坦尼克号数据集,并尝试针对分类变量生成一对数值变量图。我可以使用 Seaborn'scatplot绘制一个数字变量与一个分类变量的图:
import seaborn as sns
sns.catplot(data=train, x='Fare', y='Sex')
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试使用 PairGrid 根据分类变量绘制数字变量:
x_vars = ['Fare']
y_vars = ['Sex']
g = sns.PairGrid(train, x_vars=x_vars, y_vars=y_vars)
g.map(sns.catplot)
Run Code Online (Sandbox Code Playgroud)
它失败并出现错误:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-75-c284a7cfd727> in <module>
9 #g.map_diag(lambda x, **kwargs: sns.catplot(x, x, **kwargs), jitter=True, kind="bar")
10 #g.map(sns.scatterplot, y_jitter=1)#, hue=train["Survived"])
---> 11 g.map(sns.catplot)#, hue=train["Survived"])
~/MLProject/book1/lib/python3.8/site-packages/seaborn/axisgrid.py in map(self, func, **kwargs)
1363 row_indices, col_indices = np.indices(self.axes.shape)
1364 indices = zip(row_indices.flat, col_indices.flat)
-> 1365 self._map_bivariate(func, indices, **kwargs)
1366 return self
1367
~/MLProject/book1/lib/python3.8/site-packages/seaborn/axisgrid.py in …Run Code Online (Sandbox Code Playgroud) 使用react-table,我可以很好地过滤数据,但希望它更动态
现在我正在努力完成的是过滤图表中的数据,使其更有意义,部分方法是将来自单一品牌的产品聚集在一个条形图中,以及删除过多的品牌,这些品牌使信息更难理解.
这是我正在使用的 Table 组件
import React from 'react'
import {
useTable,
usePagination,
useSortBy,
useFilters,
useGroupBy,
useExpanded,
useRowSelect,
} from 'react-table'
import matchSorter from 'match-sorter'
// import makeData from '../example/makedata.js'
// Create an editable cell renderer
const EditableCell = ({
value: initialValue,
row: { index },
column: { id },
updateMyData, // This is a custom function that we supplied to our table instance
editable,
}) => {
// We need to keep and update the state of the cell …Run Code Online (Sandbox Code Playgroud) javascript data-visualization typescript reactjs react-table
python ×5
matplotlib ×4
javascript ×3
d3.js ×2
seaborn ×2
bar-chart ×1
bokeh ×1
interaction ×1
pandas ×1
plot ×1
plotly ×1
python-3.x ×1
react-table ×1
reactjs ×1
scatter ×1
svg ×1
typescript ×1