Django 404尾随斜线(Django 404 on trailing slash)
当我使用以下urlconf时:
url( r'^titles/(?P<order_item_id>\d+)/localized$', 'metadataorder.title.views.localized_metadata', name='localized_metadata', ),
有用。 但是,如果我使用尾部斜杠(我的所有其他网址都使用),则为404s。
url( r'^titles/(?P<order_item_id>\d+)/localized/$', 'metadataorder.title.views.localized_metadata', name='localized_metadata', ),
为什么会发生这种情况,我需要改变什么?
When I use the following urlconf:
url( r'^titles/(?P<order_item_id>\d+)/localized$', 'metadataorder.title.views.localized_metadata', name='localized_metadata', ),
it works. However if I use the trailing slash (which all my other urls use), it 404s.
url( r'^titles/(?P<order_item_id>\d+)/localized/$', 'metadataorder.title.views.localized_metadata', name='localized_metadata', ),
Why is this occuring and what do I need to change?
原文:https://stackoverflow.com/questions/14430075
最满意答案
您可以使用
sns.boxplot
和sns.stripplot
函数中的order
参数来订购“框”。 下面是一个如何执行此操作的示例(因为“最大到最低”并不完全清楚您的意思,即您希望根据条目对条目进行排序,我假设您要根据总和对它们进行排序对于他们的“距离”值,如果要根据不同的值对它们进行排序,您应该能够编辑解决方案以满足您的需求):import numpy as np import seaborn as sns sns.set(style="ticks", palette="muted", color_codes=True) # Load the example planets dataset planets = sns.load_dataset("planets") # Determine the order of boxes order = planets.groupby(by=["method"])["distance"].sum().iloc[::-1].index # Plot the orbital period with horizontal boxes ax = sns.boxplot(x="distance", y="method", data=planets, order=order, whis=np.inf, color="c") # Add in points to show each observation sns.stripplot(x="distance", y="method", data=planets, order=order, jitter=True, size=3, color=".3", linewidth=0) # Make the quantitative axis logarithmic ax.set_xscale("log") sns.despine(trim=True)
这个修改过的代码(注意在
sns.boxplot
和sns.stripplot
函数中使用order
参数)将产生下图:You can use the
order
argument in thesns.boxplot
andsns.stripplot
functions to order your "boxes". Here is an example of how to do this (since it is not completely clear what you mean by "greatest to lowest", i.e. which variable you want to sort the entries based on, I am assume you want to sort them based on the sum of their "distance" values, you should be able to edit the solution to fit your needs if you want to sort them based on a different value):import numpy as np import seaborn as sns sns.set(style="ticks", palette="muted", color_codes=True) # Load the example planets dataset planets = sns.load_dataset("planets") # Determine the order of boxes order = planets.groupby(by=["method"])["distance"].sum().iloc[::-1].index # Plot the orbital period with horizontal boxes ax = sns.boxplot(x="distance", y="method", data=planets, order=order, whis=np.inf, color="c") # Add in points to show each observation sns.stripplot(x="distance", y="method", data=planets, order=order, jitter=True, size=3, color=".3", linewidth=0) # Make the quantitative axis logarithmic ax.set_xscale("log") sns.despine(trim=True)
This modifed code (notice the use of the
order
argument in thesns.boxplot
andsns.stripplot
functions) will produce the following figure:
相关问答
更多-
您链接的问题使用了一个factorplot 。 factorplot返回自己的类,该类具有一个名为set_xticklabels(rotation) 。 这与matplotlib Axes的set_xticklabels方法不同。 在链接问题的答案中,您还可以使用其他选项 ax = sns.boxplot(x='categories', y='oxygen', hue='target', data=df) ax.set_xticklabels(ax.get_xticklabels(),rotation=30 ...
-
在这方面,Seaborn似乎与matplotlib一样: tips = sns.load_dataset("tips") ax = sns.boxplot(x=tips["total_bill"], whis=[5, 95]) plt.grid(True) plt.boxplot(tips["total_bill"], whis=[5, 95], vert=False) plt.grid(True) 我猜seaborn只是传递给matplotlib方法。 docstring可能是从早期版本的matplo ...
-
seaborn boxplot的小块(Subplot for seaborn boxplot)[2023-10-03]
我们用子图创建图: f, axes = plt.subplots(1, 2) 其中轴是每个子图的数组。 然后我们用参数ax告诉每个我们想要他们的子图。 sns.boxplot( y="b", x= "a", data=df, orient='v' , ax=axes[0]) sns.boxplot( y="c", x= "a", data=df, orient='v' , ax=axes[1]) 结果是: We create the figure with the subplots: f, ax ... -
使用color参数: import seaborn as sns tips = sns.load_dataset("tips") sns.boxplot(x="day", y="tip", data=tips, color="seagreen") Use the color parameter: import seaborn as sns tips = sns.load_dataset("tips") sns.boxplot(x="day", y="tip", data=tips, color="seag ...
-
如何在Seaborn boxplot中编辑胡须,传单,帽子等属性(How to edit properties of whiskers, fliers, caps, etc. in Seaborn boxplot)[2023-06-15]
您需要编辑存储在ax.lines的Line2D对象。 下面是一个脚本来创建一个箱形图(基于这里的例子),然后根据你的问题中的样式编辑线条和艺术家(即没有填充,所有的线条和标记都是相同的颜色等) 您还可以修复图例中的矩形面片,但需要使用ax.get_legend().get_patches() 。 我还在第二个Axes上绘制了原始的boxplot作为参考。 import matplotlib.pyplot as plt import seaborn as sns fig,(ax1,ax2) = plt.su ... -
交换x和y列名称: import seaborn as sns sns.boxplot(x="weight_cat" y="Height", data=data) 目前,您正在尝试创建一个包含尽可能多的箱图的图表,因为有不同的高度值(24503)。 这对我的数据有用: 编辑 如果要水平显示箱线图,可以使用orient参数提供方向: sns.boxplot(x='Height', y='weight_cat', data=data, orient='h') 请注意,在这种情况下,交换x和y标签(如您的问题 ...
-
我认为这里以简单的方式工作将需要一个像这样的数据帧: 价值方法 1.0 A p0 2.1 A p0 3.0 A p1 1.3 B p0 4.3 B p1 那么你可以用sns.boxplot(data=df, hue='method', x='p', y='value')得到你想要的sns.boxplot(data=df, hue='method', x='p', y='value') 我正在研究如何将df1和df2轻松地合并到像这样的数据框架中,但我不是真正的熊猫专家。 编辑:想出来,需要使用melt方法: ...
-
这可能是一个丑陋的解决方案,但它有效,所以谁在乎 fig, ax = plt.subplots(1, 1) boxplot = sns.boxplot(x="Regularisierungsparameter", y="F1", data=data.sort("Regularisierungsparameter"), ax=ax) labels = ['%.5f' % float(t.get_text()) for t in ax.get_xticklabels()] ax.set_xticklabels( ...
-
我鼓励你熟悉使用熊猫从数据框中提取定量信息。 例如,你可以做一件简单的事情来获得你正在寻找的值(和其他有用的值): planets.groupby("method").distance.describe().unstack() 它为每个方法打印一个有用值的表。 或者,如果你只是想要中位数: planets.groupby("method").distance.median() I would encourage you to become familiar with using pandas to ex ...
-
您可以使用sns.boxplot和sns.stripplot函数中的order参数来订购“框”。 下面是一个如何执行此操作的示例(因为“最大到最低”并不完全清楚您的意思,即您希望根据条目对条目进行排序,我假设您要根据总和对它们进行排序对于他们的“距离”值,如果要根据不同的值对它们进行排序,您应该能够编辑解决方案以满足您的需求): import numpy as np import seaborn as sns sns.set(style="ticks", palette="muted", color_cod ...