[英]Plotly: How to make different plots using plotly as a plotting backend for pandas?
You can define which plot type you'd like to produce through the kind
argument in:您可以通过以下中的
kind
参数定义要生成的 plot 类型:
df.plot(kind='line')
kind='line'
produces the very same plot as in the question. kind='line'
产生与问题相同的 plot 。 Valid options are:有效的选项是:
['scatter', 'line', 'area', 'bar',
'barh', 'hist', 'box', 'violin',
'strip', 'funnel', 'density_heatmap',
'density_contour', 'imshow']
You can easily study them all by running:您可以通过运行轻松地研究它们:
for k in kinds[:-1]:
df.plot(kind=k).show()
Notice that I've used kinds[:-1]
.请注意,我使用了
kinds[:-1]
。 This is because imshow
is for image data and requires a dataset a bit more complicated than [1,2,3,4,5,6]
.这是因为
imshow
用于图像数据,并且需要比[1,2,3,4,5,6]
更复杂的数据集。 Please refer to this and Plotting an image with imshow from a pandas dataframe请参考此内容并从 pandas dataframe 中使用 imshow 绘制图像
In order to set the titles and title colors for all other options, here's a complete code snippet:为了为所有其他选项设置标题和标题 colors,这里有一个完整的代码片段:
import random
import pandas as pd
random.seed(123)
df = pd.DataFrame({'x':[1,2,3,4,5,6]})
pd.options.plotting.backend = "plotly"
kinds = ['scatter', 'line', 'area', 'bar', 'barh', 'hist', 'box', 'violin', 'strip', 'funnel', 'density_heatmap', 'density_contour', 'imshow']
for k in kinds[:-1]:
fig = df.plot(kind=k, title = k)
fig.update_layout(title = dict(font=dict(color='#EF553B')))
fig.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.