每当我在matplotlib中调用show()
时,绘图窗口会出现在所有其他窗口后面,我必须尽量减少所有内容才能看到它。有什么方法可以阻止这个或以编程方式将它带到前面。在OSX Lion上。 Python 2.7
答案 0 :(得分:1)
不完全是您问题的答案,但我使用ipython而不是默认的python控制台。使用ipython --pylab
启动它时我可以绘制例如输入
>> plot([1,3,2])
并在前面弹出情节。它还有一些非常好的功能;)
答案 1 :(得分:1)
Matplotlib开发人员似乎意识到了这个问题。但是看看https://github.com/matplotlib/matplotlib/issues/596看起来好像它会有一段时间才能得到一个解决方案,显然是因为有些人发现它很烦人的数字。显示(#34)抢断"屏幕空间。
答案 2 :(得分:1)
好吧。该答案在对已接受答案的注释中给出,但是我认为应该很好地解决此问题,因此应该将其作为一个单独的位置放置。除了作者的问题外,我还遇到了问题:matplotlib窗口不在活动窗口的托盘中,因此public class RecyclerViewListItem {
private String name;
private String description;
private FrameLayout frameLayoutA;
private FrameLayout frameLayoutB;
private String newstatus;
private String glutenstatus;
private String suitability;
public RecyclerViewListItem(){}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public FrameLayout getFrameLayoutA() {
return frameLayoutA;
}
public void setFrameLayoutA(FrameLayout frameLayoutA) {
this.frameLayoutA = frameLayoutA;
}
public FrameLayout getFrameLayoutB() {
return frameLayoutB;
}
public void setFrameLayoutB(FrameLayout frameLayoutB) {
this.frameLayoutB = frameLayoutB;
}
public String getNewstatus() {
return newstatus;
}
public void setNewstatus(String newstatus) {
this.newstatus = newstatus;
}
public String getGlutenstatus() {
return glutenstatus;
}
public void setGlutenstatus(String glutenstatus) {
this.glutenstatus = glutenstatus;
}
public String getSuitability() {
return suitability;
}
public void setSuitability(String suitability) {
this.suitability = suitability;
}
}
无法切换到该窗口。
更改matplotlib的默认后端public class MyFragment extends android.support.v4.app.Fragment {
private FrameLayout frameLayoutA;
private FrameLayout frameLayoutB;
public MyFragment() {}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_rv, container, false);
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
View v = getView();
assert v != null;
recyclerView = v.findViewById(R.id.my_recyclerview);
linearLayoutManager = new LinearLayoutManager(getActivity());
MyRecyclerAdapter adapter = new MyRecyclerAdapter(getContext(), getHeader(), getListItems());
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setAdapter(adapter);
super.onActivityCreated(savedInstanceState);
}
RecyclerView recyclerView;
LinearLayoutManager linearLayoutManager;
public RecyclerViewHeader getHeader()
{
RecyclerViewHeader header = new RecyclerViewHeader();
header.setHeading("Desserts");
header.setSubheading("All made fresh daily");
return header;
}
public List<RecyclerViewListItem> getListItems()
{
List<RecyclerViewListItem> listItems = new ArrayList<>();
RecyclerViewListItem itemA = new RecyclerViewListItem();
itemA.setName("Crème Brûlée");
itemA.setDescription("Caramalised vanilla crème with an almond tuile");
itemA.setFrameLayoutA(new CustomDrawingA(getContext()));
itemA.setFrameLayoutB(new CustomDrawingB(getContext()));
itemA.setNewstatus(" New ");
itemA.setGlutenstatus("Gluten free");
itemA.setSuitability("Suitable for vegetarians" + "\n" + "Suitable for coeliacs" + "\n" + "Halal friendly" + "\n" + "Kosher friendly");
listItems.add(itemA);
RecyclerViewListItem itemB = new RecyclerViewListItem();
itemB.setName("Bûche de Noël");
itemB.setNewstatus(" New ");
itemB.setGlutenstatus("Gluten free");
itemB.setSuitability("Suitable for vegetarians" + "\n" + "Suitable for coeliacs");
listItems.add(itemB);
RecyclerViewListItem itemC = new RecyclerViewListItem();
itemC.setName("Croquembouche");
itemC.setNewstatus(" New ");
itemC.setGlutenstatus("Gluten free");
itemC.setSuitability("Suitable for vegetarians" + "\n" + "Suitable for coeliacs");
listItems.add(itemC);
}
解决了所有问题。您可以像下面这样在您的代码中立即尝试:
<Alt>+<Tab>
macosx
可能不会出现在您的系统中,请选择一个。您可以找到它们:
import matplotlib
matplotlib.use("Qt5agg")
如果有帮助,那么您可能想要更改配置中的后端。为此,请首先找到它:
Qt5agg
然后更改import matplotlib.rcsetup as rcsetup
print(rcsetup.all_backends)
的值:
import matplotlib
matplotlib.matplotlib_fname()
到您的后端。我最后使用了:
backend:
答案 3 :(得分:0)
它可能是特定于操作系统的,但是使用交互式绘图(在您指示后立即绘制)会导致数字在Ubuntu上生成时出现:
import pylab as P
P.ion()
P.figure(1)
P.plot([1,2,3],[1,4,9])
答案 4 :(得分:0)
我和nickponline有相同的设置。对我有用的是:
from pylab import get_current_fig_manager()
get_current_fig_manager().window.raise_()
如果你有多个数字,这只会提升当前活跃的数字。对于这种情况,我发现以下工作:
fig1=figure(1)
cfm1=get_current_fig_manager().window
fig2=figure(2)
cfm2=get_current_fig_manager().window
...
cfm1.activateWindow()
cfm1._raise()
pause(.1) # or something else that uses up some time
cfm2.activateWindow()
cfm2.raise_()