我正在寻找一种解决方案来避免文本标签中的文本重叠。我用散点图创建图像。也许这里有自动化。
from pandas import util
import plotly.express as px
import plotly.graph_objects as go
df = util.testing.makeDataFrame()
df_keyfigures_all = df[['A','B']]
fig = px.scatter(df_keyfigures_all, x="A", y="B",size_max=60,
text=df_keyfigures_all.index)
fig.update_traces(textposition='top center')
fig.layout = go.Layout(yaxis=dict(tickformat=".0%"), xaxis=dict(tickformat=".0%"),
yaxis_title="A", xaxis_title="B")
fig.update_layout(showlegend=False)
plotly.io.write_image(fig, file='keyfigures.png', format='png')
Run Code Online (Sandbox Code Playgroud)
您好,我尝试弄清楚如何在每个国家/地区仅使用一种颜色 - 填充颜色。以下示例给出了每个国家/地区的透明颜色和深色颜色的混合。我希望只有一种颜色。感谢帮助
import plotly
#import plotly.graph_objects as go
import plotly.express as px
df = px.data.gapminder()
fig = px.area(df, x="year", y="pop", color="country",
groupnorm='fraction')
plotly.io.write_image(fig, file='areatest.png', format='png')
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Plotly 中制作一个带有虚线和标记线的折线图。在本例中,我希望代表“加拿大”的线是虚线。我已经弄清楚如何更改宽度和颜色,但不知道如何使线条虚线。我原来的 DF 更大,所以 go.scatter 对我来说不是一个解决方案。谢谢您的帮助!
import plotly.express as px
# data
df = px.data.gapminder()
df = df[df['country'].isin(['Canada', 'USA', 'Norway', 'Sweden', 'Germany'])]
# plotly
fig = px.line(df, x='year', y='lifeExp',
color='country')
# color "Canada" black and change the width of the line
fig.update_traces(patch={"line": {"color": "black", "width": 4}},#
selector={"legendgroup": "Canada"})
#i tried to extend the code with dash and mode, but do not work:
#fig.update_traces(patch={"line": {"color": "black", "width": 4, "dash": 'dot', "mode": 'lines+markers'}},
plotly.io.write_image(fig, file='testline.png', format='png')
Run Code Online (Sandbox Code Playgroud)
我使用 FPDF 通过 python 生成 pdf。我有一个问题正在寻找解决方案。在“图像”文件夹中,我想在一页上显示每张图片。我就是这么做的——也许并不优雅。不幸的是我无法将图片移到右侧。看起来 pdf_set_y 在循环中不起作用。
from fpdf import FPDF
from os import listdir
from os.path import isfile, join
onlyfiles = [f for f in listdir('../images') if isfile(join('../images', f))]
pdf = FPDF('L')
pdf.add_page()
pdf.set_font('Arial', 'B', 16)
onlyfiles = ['VI 1.png', 'VI 2.png', 'VI 3.png']
y = 10
for image in onlyfiles:
pdf.set_x(10)
pdf.set_y(y)
pdf.cell(10, 10, 'please help me' + image, 0, 0, 'L')
y = y + 210 #to got to the next page
pdf.set_x(120)
pdf.set_y(50)
pdf.image('../images/' + …Run Code Online (Sandbox Code Playgroud) 我尝试生成一个新的数据帧(expected_result),它基于两个现有的数据帧(排名、值)和一个过滤器。两个现有的数据名具有相同的标头和索引。如果数据帧“rank”中的值等于或小于filter_var,则新数据帧应显示数据帧“value”的值。如果排名高于filter_var = show "nan"
import pandas as pd
#df 1 Rank
ranking = {'Stock A':[1, 1, 1, 1],
'Stock B':[3, 3, 4, 4],
'Stock C':[4, 4, 3, 2],
'Stock D':[2, 2, 2, 3],
}
rank = pd.DataFrame(ranking)
#df 2 values
values = {'Stock A':[101, 102, 103, 104],
'Stock B':[99, 99, 99 , 99],
'Stock C':[99, 98, 100, 103],
'Stock D':[100, 100, 100, 102],
}
value = pd.DataFrame(values)
#Filter
filter_var = 2 #better or equal
#expecet result
results = {'Stock A':[101, …Run Code Online (Sandbox Code Playgroud)