我试图在matplotlib中使用单独的y轴覆盖一组条形图。我无法在任何地方找到一个例子,并尝试了ax.set_zorder()
和ax2.set_alpha()所能想到的一切。有没有办法从箱形图中设置背景不透明? ax.patch.set_facecolor('None')
完全删除背景......
这是我尝试过的:
import matplotlib.pyplot as plt
import numpy as np
example_data = [1,2,1],[1,2,2,2],[3,2,1]
data = [i for i in example_data]
data_len = [len(i) for i in example_data]
labels = ['one','two','three']
plt.figure()
fig, ax = plt.subplots()
plt.boxplot(data)
ax.set_xticklabels(labels,rotation='vertical')
ax2 = ax.twinx()
ax2.bar(ax.get_xticks(),data_len,color='yellow', align='center')
ax2.set_zorder(1)
ax.set_zorder(2)
ax2.set_alpha(0.1)
ax.patch.set_facecolor('None')
plt.show()
提前感谢您的帮助。
答案 0 :(得分:1)
如何只更改绘图的顺序,以便在条形图后显示方框图?例如:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.phongponix.trackingbodybuilding.MainActivity$PlaceholderFragment">
<ListView android:id="@+id/lvExerciseList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="50dp"
></ListView>
</RelativeLayout>
这会给你: