2011-01-18 9 views
1

가하기 matplotlib로 작업 할 때이 잘 작동RC 변수는, 내가 라인을 설정하기 위해 노력하고있어

matplotlib.rc('lines', linewidth=0.5) 

사용하여 그래프를 생성하는 웹 응용 프로그램에서하기 matplotlib에 대한 너비 웹 응용 프로그램에서 축 대화 형 모드에서,하지만 내 웹 응용 프로그램에서이 효과가 없습니다, 내가 올바른 라인 폭을 얻을 수있는 유일한 방법은, 개별 호출에 인수를 제공하는 것입니다 예 :

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 호출이 작동하도록 만드시겠습니까?

이 같은 모습에 그릴 그림을 얻기를 위해 사용하고 코드 : 당신이 게시 한 무엇

@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() 
+0

matplotlib/pyplot 컨텍스트에서'rc'가 의미하는 바는 무엇입니까? – shailenTJ

답변

1

작동합니다. 레퍼런스로서, 다음은 python 2.6과 matplotlib 1.0을 사용하여 완벽하게 작동합니다.

from contextlib import contextmanager 

import matplotlib as mpl 
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas 
from matplotlib.figure import Figure 

@contextmanager 
def render_plot(w=8,h=8): 
    fig = Figure(figsize=(w,h))   
    canvas = FigureCanvas(fig) 
    mpl.rc('lines', linewidth=5) 
    yield fig 
    s = file('temp.png', 'w') 
    canvas.print_figure(s) 

with render_plot() as fig: 
    ax = fig.add_subplot(111) 
    ax.plot(range(10)) 

alt text

는 시스템이 예 작동합니까?

관련 문제