Ipython Notebook & Matplotlib: How to wrap a plot within a html div?

ε祈祈猫儿з 提交于 2019-12-24 12:51:59

问题


I want to add some css to part of my plot, (specifically, I want to set float:left).

How can I produce the plot within a div, so I can use css to control its layout?

For example, for code

def simple_plot(ax = None):
    if ax is None:
        fig, ax = plt.subplots()
    a = [1,2,3,4]
    b = [3,4,5,6]
    plt.plot(a, b,'-', color='black')

simple_plot()

The default output html in Ipython Notebook is

<div class="output_area">
  <div class="prompt"></div>
  <div class="output_subarea output_png">
    <img src="data:image/png;>

For some plots, I want to wrap it with a html/css, something like this:

<div class="output_area">
  <div class="prompt"></div>
  <div class="output_subarea output_png">
    <div class="custom-css-for-matplotlib"> ## custom html/css code wrapper

How can I do that?

It would be fantastic if I can simply code in cell like:

<div class='custom css class'>
simple_plot()
</div>

来源:https://stackoverflow.com/questions/35425743/ipython-notebook-matplotlib-how-to-wrap-a-plot-within-a-html-div

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!