我正在创建一个频率图,其中也绘制了 NA 值。我试图在 x 轴刻度中以不同的方式为 N/A 值着色。我知道如何在 matplotlib 中做到这一点,但似乎无法弄清楚如何使用 plotly 来做到这一点。
我尝试使用值列表更新 tickcolors 和 tickfonts,但它只需要这两个属性的单个值。请看下面的代码
# Doesn't work - plotly expects a single value for tickcolor
fig.update_xaxes(
tickangle = -60,
tickcolor = ['black', 'black', 'black', 'black', 'red']
)
# In matplotlib the following code works fine
# It checks the text for xticklabels and changes color if it equals 'N/A'
_ = [xl.set_color('red') for xl in plt.gca().get_xticklabels() if xl.get_text() == 'N/A / Missing']
Run Code Online (Sandbox Code Playgroud)
我希望它看起来像这样 - 这是我的 matplotlib 代码预期输出的输出
我想使用 ggplot2 和 plotly 在 R 中模拟 Excel 平滑样式。
套餐
library(dplyr)
library(tibble)
library(ggplot2)
library(plotly)
library(ggforce) #only for geom_bspline() in example below (other smoothing functions can be used)
library(scales) #only for percent() formatting below
Run Code Online (Sandbox Code Playgroud)
示例数据集
df <- tibble(Group = rep(LETTERS[1:2], each = 10),
x = rep(1:10, 2),
y = c(2, 5, 9, 15, 19, 19, 15, 9, 5, 2,
1, 0, 3, 2, 3, 4, 14, 24, 24, 25)*0.01)
Run Code Online (Sandbox Code Playgroud)
我想要的是
到目前为止我所拥有的
(df %>%
ggplot(aes(x, y)) +
geom_point(aes(color = Group)) +
ggforce::geom_bspline(aes(group …Run Code Online (Sandbox Code Playgroud) 如果将鼠标悬停在图例上,如何显示与图例中所述不同的跟踪名称?
目前我像这样推送我的配置:
...
const chart_entry = {
x: x,
y: y,
type: 'scatter',
name: legendName
};
this.graph.data.push(chart_entry);
...
Run Code Online (Sandbox Code Playgroud)
但是,通过这种方式,无论是在图例中还是在将鼠标悬停在一行上时,都会对图例中的相同名称进行寻址(legendName 变量)。
但我希望悬停有一个单独的名字。
那可能吗?
所以我正在尝试通过 Plotly 库编写烛台图表,并尝试在我的代码中添加移动平均线。我搜索了许多代码以在我的代码中实现 MA,但我无法弄清楚如何在同一烛台图表中添加 MA 线。
等待有人帮我解决这个问题。
import shrimpy
import pandas_datareader as web
import pandas as pd
import datetime
import plotly.express as px
import numpy as np
import plotly.graph_objects as go
# sign up for the Shrimpy Developer APIs for your free API keys
public_key = ''
secret_key = ''
# collect the historical candlestick data
client = shrimpy.ShrimpyApiClient(public_key, secret_key)
candles = client.get_candles(
'binance', # exchange
'BNB', # base_trading_symbol
'BTC', # quote_trading_symbol
'1d' # interval
)
dates = []
open_data …Run Code Online (Sandbox Code Playgroud) 我有四个单独的饼图,它们都具有相同的指定配色方案(除了数据框之外,代码是相同的)。
指定颜色是因为我想将它们在 4 个网格图中与一个图例组合在一起,为 5 组中的每一组使用相同的指定颜色(即,当未指定颜色时,颜色会根据大小自动分配)团体)。
示例数据:
# Data
g = c("D","L","X","A","N","B")
v = c(49,14,9,7,6,5)
df1 = data.frame(group = g, value = v)
set.seed(9) # Just for reproductibility
df2 = data.frame(group = sample(g,size = nrow(df1),replace = F),
value = sample(v,size = nrow(df1),replace = F)
)
set.seed(8)
df3 = data.frame(group = sample(g,size = nrow(df1),replace = F),
value = sample(v,size = nrow(df1),replace = F)
)
set.seed(7)
df4 = data.frame(group = sample(g,size = nrow(df1),replace = F),
value = sample(v,size = nrow(df1),replace = F) …Run Code Online (Sandbox Code Playgroud) 我认为默认颜色循环将是(某些变体)['blue', 'red', 'green', 'purple', 'orange']如下图所示:
情节 1:
代码 1:
import plotly
import plotly.express as px
gapminder = px.data.gapminder()
gapminder2007=gapminder.query("year==2007")
px.scatter(gapminder2007, x='gdpPercap', y='lifeExp', color="continent")
Run Code Online (Sandbox Code Playgroud)
至少这似乎是循环的顺序,因为Oceania从大陆中省略会给你这个:
现在其余颜色的顺序是相同的,除了最后一个橙色的外观(只是表明颜色的应用不是随意的)。
我认为这可以使用plotly.colors.DEFAULT_PLOTLY_COLORS它来检索,这会给你:
['rgb(31, 119, 180)',
'rgb(255, 127, 14)',
'rgb(44, 160, 44)',
'rgb(214, 39, 40)',
'rgb(148, 103, 189)',
'rgb(140, 86, 75)',
'rgb(227, 119, 194)',
'rgb(127, 127, 127)',
'rgb(188, 189, 34)',
'rgb(23, 190, 207)']
Run Code Online (Sandbox Code Playgroud)
但这些颜色的顺序是 ['blue', 'orange', 'green', 'red']...
那么,当设置为in时, plotly 表达遵循什么颜色循环?color="continent"px.scatter(gapminder2007, x='gdpPercap', y='lifeExp', color="continent")
我也试着往下看help(px.colors) …
目前,plotly express 树形图仅显示树形图中的标签。如何在标签旁边包含值?
python data-visualization plotly plotly-python plotly-express
我有一个这样的情节,想在文本“今天”的行上方添加文本。
我正在尝试使用注释
annots.append(dict(x='2020-03-29',y=len(df)+1,text='<b>Today<b>', showarrow=False, font=dict(color='black')))
Run Code Online (Sandbox Code Playgroud)
我在 Python 中绘制了 scatter_geo 图。
import plotly.express as px
import pandas as pd
rows=[['501-600','65','122.58333','45.36667'],
['till 500','54','12.5','27.5'],
['more 1001','51','-115.53333','38.08'],
['601-1000','54','120.54167','21.98'],
]
colmns=['bins','data','longitude','latitude']
df=pd.DataFrame(data=rows, columns=colmns)
fig=px.scatter_geo(df,lon='longitude', lat='latitude',color='bins',
opacity=0.5,
projection="natural earth")
fig.show()
Run Code Online (Sandbox Code Playgroud)
如果我只有一条数据痕迹,是否有可能在图例标签中自定义顺序?
因为现在图例中的标签如下所示:
501-600
till 500
more 1001
601-1000
Run Code Online (Sandbox Code Playgroud)
我需要让它们看起来像这样:
till 500
501-600
601-1000
more 1001
Run Code Online (Sandbox Code Playgroud)