matplotlib 中的 RC 变量不适用于 Web 应用程序中的图形、轴
我正在尝试在使用交互模式下使用 matplotlib 时生成图形的 Web 应用程序中设置 matplotlib 的线宽
matplotlib.rc('lines', linewidth=0.5)
,但在我的 Web 应用程序中它没有效果,这是我获得正确线宽的唯一方法是通过在各个调用上提供参数,即:
vals = map(itemgetter(1), sorted(series1.items(), reverse=True))
group1_rects = ax.barh(ind, vals, width, color='r', snap=True, linewidth=0.5)
vals = map(itemgetter(1), sorted(series2.items(), reverse=True))
group2_rects = ax.barh(ind+width, vals, width, color='b', linewidth=0.5)
是否涉及一些技巧来使 matplotlib.rc 调用在 Web 应用程序中工作?
我用来获取要绘制的图形的代码如下所示:
@contextmanager
def render_plot(w=8,h=8):
fig = Figure(figsize=(w,h))
canvas = FigureCanvas(fig)
response.content_type = 'image/png'
#Here is where I hope to put RC settings
matplotlib.rc('lines', linewidth=0.5)
yield fig
s = StringIO()
canvas.print_figure(s)
response.content = s.getvalue()
I'm trying to set line widths for matplotlib in a web application that generates graphs using
matplotlib.rc('lines', linewidth=0.5)
This works fine when working with matplotlib in interactive mode, but in my web application it has no effect, and the only way I can get the correct line widths is by supplying the argument on the individual calls, i.e.:
vals = map(itemgetter(1), sorted(series1.items(), reverse=True))
group1_rects = ax.barh(ind, vals, width, color='r', snap=True, linewidth=0.5)
vals = map(itemgetter(1), sorted(series2.items(), reverse=True))
group2_rects = ax.barh(ind+width, vals, width, color='b', linewidth=0.5)
Is there some trick involved to make the matplotlib.rc call work in web apps?
The code I'm using for getting a figure to draw on looks like this:
@contextmanager
def render_plot(w=8,h=8):
fig = Figure(figsize=(w,h))
canvas = FigureCanvas(fig)
response.content_type = 'image/png'
#Here is where I hope to put RC settings
matplotlib.rc('lines', linewidth=0.5)
yield fig
s = StringIO()
canvas.print_figure(s)
response.content = s.getvalue()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您发布的内容应该有效。作为参考,以下内容非常适合我使用 python 2.6 和 matplotlib 1.0。
此示例适用于您的系统吗?
What you've posted should work. Just as a reference, the following works perfectly for me using python 2.6 and matplotlib 1.0.
Does this example work on your system?