English 中文(简体)
• 如何在降幅变化值出现时更新轴心。 Bar(剥削)?
原标题:How to update axes when value on dropdown changes with go.Bar() (plotly)?

I trying to update the xaxis_title_text (update_layout) and the tickvals and ticktext (update_xaxes) when the dropdown value changes. I have tried to adapt the Plotly examples (link) and this answer, but I am stuck with the axes updates. In Figures 1 and 2, we can see from Figure 1 to Figure 2 that the axes do not update when the dropdown changes. Tkx for the help with that. enter image description here Figure 1 enter image description here Figure 2

<>/strong>:

import pandas as pd
import numpy as np
import plotly.graph_objects as go

### My df has more than 1,5M rows with 79 columns. Each column may vary the scale of the number.
### E.g.: Age, weight, income, etc aren t normalized.
df = pd.DataFrame() # any dataframe to compute a histogram
num_cols = df.columns

def compute_bins(x, bins, return_var):
   hist, bins_edges = np.histogram(x, bins=bins)
   bins_text = [f"({np.round(bins_edges[i],2)}, {np.round(bins_edges[i+1],2)}]" for i in range(len(bins_edges)-1) ]

   if return_var ==  h :
      return hist
   else:
      return bins_text

hist = compute_bins(x=df[x_title].values, bins=10, return_var= h )
hist = compute_bins(x=df[x_title].values, bins=10, return_var= b )

fig = go.Figure(go.Bar(x=np.array(range(len(bins_text))), y=hist))

my_buttons = [dict(
                   mehotd= update ,
                   args=[{"y": [ compute_bins(x=df[x_title].values, bins=10, return_var= h ),  underfined  ]
                          "x": [ compute_bins(x=df[x_title].values, bins=10, return_var= h ),  underfined  ]}
                        ],
                   label = c
                  ) for k, c in enumerate(num_cols)]

fig.update_axes(tickvals==np.array(range(len(bins_text))), ticktext=bins_text)
fig.update_layout(bargap=0, xaxis_title_text=x_title, yaxis_title_text= Count ,
                  updatemenus=[dict(
                                   active=0,
                                   x=0,y=1.2,
                                   xanchor= left ,
                                   yanchor= top ,
                                   buttons=my_buttons
                              )]
                  )

问题回答

作为减少排放的投入值,环境与图格和图格有关。 需要布局。 由于你没有提交任何数据,我已经用属地抽样数据修改了你的代码。

import pandas as pd
import numpy as np
import plotly.graph_objects as go
import plotly.express as px

df = px.data.tips()
num_cols = df.columns[:2]

x_title =  total_bill 

def compute_bins(x, bins, return_var):
   hist, bins_edges = np.histogram(x, bins=bins)
   bins_text = [f"({np.round(bins_edges[i],2)}, {np.round(bins_edges[i+1],2)}]" for i in range(len(bins_edges)-1) ]

   if return_var ==  h :
      return hist
   else:
      return bins_text

hist = compute_bins(x=df[x_title].values, bins=10, return_var= h )
bins_text = compute_bins(x=df[x_title].values, bins=10, return_var= b )
    
fig = go.Figure(go.Bar(x=bins_text, y=hist))

my_buttons = [dict(
                   method= update ,
                   args=[{"y": [compute_bins(x=df[c].values, bins=10, return_var= h )],
                          "x": [ compute_bins(x=df[c].values, bins=10, return_var= b )]},
                         { xaxis : [compute_bins(x=df[c].values, bins=10, return_var= b )]}
                        ],
                   label = c
                  ) for k, c in enumerate(num_cols)]

fig.update_xaxes(tickvals=np.array(range(len(bins_text))), ticktext=bins_text)
fig.update_layout(bargap=0, xaxis_title_text=x_title, yaxis_title_text= Count ,
                  updatemenus=[dict(
                                   active=0,
                                   x=0,y=1.2,
                                   xanchor= left ,
                                   yanchor= top ,
                                   buttons=my_buttons
                              )]
                  )
fig.show()

“entergraph

“在此处的影像描述”/</a





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...