使用 plotly 按降序排列 X 轴
arrange X axis in descending order using plotly
我正在尝试使用 plotly
创建交互式绘图,但在订购 X 轴时遇到问题。这是我正在使用的代码:
import plotly.plotly as py
import cufflinks as cf
import pandas as pd
import plotly.tools as tls
tls.set_credentials_file(username='ladeeda', api_key='ladeeda')
cf.set_config_file(offline=False, world_readable=True, theme='pearl')
StudentModalityRetention[StudentModalityRetention['schoolyearsemester'] == 'Sem3']\
.iplot(kind='bubble', x='branch', y='retention', size='active_users', text='active_users',
xTitle='', yTitle='Retention',
filename='cufflinks/Sem3ModalityRetention')
这是生成的图:
我想按降序排列X轴或Y轴。换句话说,我希望 Y 值最高的气泡最先出现,依此类推..
如有任何帮助,我们将不胜感激。
实现目标的一种简单有效的方法是根据您的要求按降序对 pandas 数据帧进行排序,然后使用 iplot
绘制图形,这将为您提供所需的结果。这是一个简短的例子:
yourdataframe.sort_values(by='Y',\ #column name or index values according to which the dataframe is to be sorted
axis=0, #for column sorting
ascending=False, #in your case, for descending
inplace = True)\ #if you want to perform the operation inplace or return a new dataframe
.iplot(kind='bubble', x='branch', y='retention',size='active_users', text='active_users',
xTitle='', yTitle='Retention',
filename='cufflinks/Sem3ModalityRetention')
希望对你有帮助:))
我正在尝试使用 plotly
创建交互式绘图,但在订购 X 轴时遇到问题。这是我正在使用的代码:
import plotly.plotly as py
import cufflinks as cf
import pandas as pd
import plotly.tools as tls
tls.set_credentials_file(username='ladeeda', api_key='ladeeda')
cf.set_config_file(offline=False, world_readable=True, theme='pearl')
StudentModalityRetention[StudentModalityRetention['schoolyearsemester'] == 'Sem3']\
.iplot(kind='bubble', x='branch', y='retention', size='active_users', text='active_users',
xTitle='', yTitle='Retention',
filename='cufflinks/Sem3ModalityRetention')
这是生成的图:
我想按降序排列X轴或Y轴。换句话说,我希望 Y 值最高的气泡最先出现,依此类推..
如有任何帮助,我们将不胜感激。
实现目标的一种简单有效的方法是根据您的要求按降序对 pandas 数据帧进行排序,然后使用 iplot
绘制图形,这将为您提供所需的结果。这是一个简短的例子:
yourdataframe.sort_values(by='Y',\ #column name or index values according to which the dataframe is to be sorted
axis=0, #for column sorting
ascending=False, #in your case, for descending
inplace = True)\ #if you want to perform the operation inplace or return a new dataframe
.iplot(kind='bubble', x='branch', y='retention',size='active_users', text='active_users',
xTitle='', yTitle='Retention',
filename='cufflinks/Sem3ModalityRetention')
希望对你有帮助:))