Closed SerenaQYHuang closed 5 years ago
fig, axes = plt.subplots(nrows=2, ncols=2,constrained_layout=True,figsize=(30,20)) #set a 2*2 canvas, adjust layout to more flexible, adjust figure size, axes means the location of each subplots, you can refer to the following picture below to learn more.
There is a problem with the keyword argument 'constrained_layout'
@SerenaQYHuang what's the error of question2? Its good in my testing.
I searched for this and it seems that we need the matplotlib 2.2 or above to have this function. The problem is I can't install it.
Do we need an account to use this function? @ChicoXYC
from pyecharts import Bar
#to see relationship between countries with likes and bookmarks
pd_df3 = df.groupby(['country'])['bookmark'].mean().reset_index().sort_values("bookmark",ascending=False)
attr = pd_df2.country
v1 = pd_df2.likes #you can pass a list like data here
v2 = pd_df3.bookmark
bar = Bar("Countries by likes and bookmark")
bar.add("by likes", attr, v1, mark_line=["average"])
bar.add("by bookmark", attr, v2, mark_line=["average"])
bar
I got one merged bar chart instead of two: (see following)
from bokeh.plotting import figure
from bokeh.io import show, output_file
output_file("bokeh_bar.html")
pd_df5 = df.groupby(['country'])['bookmark'].mean().reset_index().sort_values("bookmark",ascending=False)[:10]
# source = ColumnDataSource(data=pd_df5)
p = figure(x_range=pd_df5.country,plot_height=350, title="Country with bookmark",
toolbar_location=None, tools="")
p.vbar(x=pd_df5.country, top=pd_df5.bookmark, width=0.9)
p.xgrid.grid_line_color = None
p.y_range.start = 0
show(p)
Does not work. (see following)
I searched for this and it seems that we need the matplotlib 2.2 or above to have this function. The problem is I can't install it.
Are you install successfully?
from pyecharts import Bar #to see relationship between countries with likes and bookmarks pd_df3 = df.groupby(['country'])['bookmark'].mean().reset_index().sort_values("bookmark",ascending=False) attr = pd_df2.country v1 = pd_df2.likes #you can pass a list like data here v2 = pd_df3.bookmark bar = Bar("Countries by likes and bookmark") bar.add("by likes", attr, v1, mark_line=["average"]) bar.add("by bookmark", attr, v2, mark_line=["average"]) bar
I got one merged bar chart instead of two: (see following)
@SerenaQYHuang this is right, you can click the legend by likes
and by bookmark
to see different charts.
from bokeh.plotting import figure from bokeh.io import show, output_file output_file("bokeh_bar.html") pd_df5 = df.groupby(['country'])['bookmark'].mean().reset_index().sort_values("bookmark",ascending=False)[:10] # source = ColumnDataSource(data=pd_df5) p = figure(x_range=pd_df5.country,plot_height=350, title="Country with bookmark", toolbar_location=None, tools="") p.vbar(x=pd_df5.country, top=pd_df5.bookmark, width=0.9) p.xgrid.grid_line_color = None p.y_range.start = 0 show(p)
Does not work. (see following)
@SerenaQYHuang I check out again, it works in my environment. Maybe we can have a meeting, I will check where it went wrong.
Do we need an account to use this function? @ChicoXYC
@SerenaQYHuang This is because I use the plot online method, which requires an account. I just updated the plot.offline
method, you can try without creating an account. https://github.com/hupili/python-for-data-and-media-communication-gitbook/blob/master/notes-week-09.md#plotly
@SerenaQYHuang have the problems solved?
All the problems are solved except for the last one
Question is not clear, closed for now and will be reopened if necessary.
The first line should be
import pandas as pd
because pyplot has already been imported before. However, pandas has not been imported.Also, I think
plt.show()
should be added to make sure the figure will be displayed