اولین بار است که به اینجا می‌آیید؟ راهنمای سایت را بخوانید!
Close Sidebar
وب‌سایت پرسش و پاسخ پارسی‌لاتک جایی برای پرسش و پاسخ درباره سیستم حروف‌چینی لاتک و بسته زی‌پرشین است. در اینجا می‌توانید سوال‌های خود را بپرسید و به سوال‌های دیگران پاسخ دهید.

محبوب‌ترین برچسب‌ها

رفع خطا جدول مراجع xepersian ریاضی‌نویسی شکل فونت فهرست مطالب شماره‌گذاری منابع bidi پانویس بیب‌تک tikz تک‌لایو parsilatex بیمر اسلاید زی‌پرشین پاورقی bibtex سربرگ نماد رسم شکل فرمول‌نویسی قالب ارجاع‌دهی biditexmaker هدر ویرایشگر beamer واژه‌نامه اندازه فونت texstudio عنوان فصل ماتریس اعمال نشدن تغییرات در پی‌دی‌اف رسم جدول bidipresentation شماره صفحه حاشیه رنگ عنوان شکل اسلاید فارسی محیط قضیه گراف مکان شکل tikzpicture حروف‌چینی کد شماره فصل enumerate tabriz_thesis نمایه align زیرنویس شکل کادر itemize فهرست اشکال الگوریتم listings عدم اجرا نیم‌فاصله متن لاتین و فارسی بسته فاصله بین خطوط قالب پایان‌نامه فرمول نصب تک‌لایو فارسی‌تک hyperref شماره فرمول glossaries کپشن نمودار خروجی لاتک حروف‌چینی چندستونی فونت فارسی و انگلیسی ماکرونویسی biditools شماره پاورقی پیوست‌ سوال امتحانی فاصله‌گذاری فرمول چندضابطه‌ای subfigure extrafootnotefeatures header texmaker pdf tex biditufte-book longtable تصویر شمارنده texlive2015 زیرنویس خطا رسم نمودار شماره‌گذاری صفحات پایان نامه دیاگرام فهرست جداول میک‌تک texlive2016 تنظیم جدول آکولاد kashida texworks caption اندیس lollipop iust-thesis multicol فصل‌نویسی شعر سوال چهارگزینه‌ای بولد تورفتگی اعداد فارسی فاصله عمودی xindy چپ‌چینی اوبونتو میکروسافت ورد قاب geometry texlive fancyhdr وسط‌چینی تک لایو 2015 عنوان بخش شماره گذاری به‌روزرسانی بسته aimc46 صفر توخالی فرمول طولانی بیرون‌زدگی xelatex کاما tcolorbox پوستر فاصله سطرها نوشتافت شکست خط tex-programming فونت اعداد pgfplots قرآن tabriz-thesis ایتالیک winedt جستجوی معکوس فلش جایابی تصویر قالب کتاب پاراگراف‌بندی بازیابی اطلاعات هایپرلینک فهرست نمادها شمارنده فصل font محیط ریاضی رسم کادر جداکننده جدول طولانی فهرست تصاویر شماره‌گذاری فرمول algorithm2e فونت بولد proof equation bidipoem eps جدول افقی عکس به‌روزرسانی پانویس چندستونی کمک مالی فاصله خطوط حروف‌چینی شعر زیرشکل minipage قلم پانویس پاراگرافی ltrfootnote پیوست computeautoilg متن فارسی و انگلیسی فرمول چندخطی neveshtuft غلط‌گیری املایی تک‌پارسی پیکان لاتکس tabular baselineskip شماره قسمت قسمت عنوان جدول
63 نفر آنلاین
0 عضو و 63 مهمان در سایت حاضرند
بازدید امروز: 12598
بازدید دیروز: 73184
بازدید کل: 25177725

دوبار ظاهر شدن legend در استفاده از pgfplots

0 رای
506 بازدید

سلام

2 سوال دارم. ممنون می شوم کمک کنید.
1- در کد کمینه زیر دوبار legend ظاهر می شود (مثلا کنار M1 را نگاه کنید)
2- چطور می توانم برای کل زیرشکلها فقط یک legend بگذارم.

کد کمینه:

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{patterns}
\usepackage{subfig} % Para hacer los subfigure
\usepackage{float}%Posicionamiento fijo con "[H]"


\begin{document}
\begin{figure}[htbp]
    \centering
    \subfloat[SF50]{
        \begin{tikzpicture}
        \begin{axis}[ybar, legend style={fill=none},
        width=0.49\linewidth,
        bar width=0.04cm,
        xlabel={$k$},
        ylabel={$\Delta ACC$}, 
        xtick=data,
        %ytick=data,
        enlarge y limits=true,
        legend pos=north west, legend entries={M1,M2,M3,M4}
        %enlarge y limits={upper,value=0.1},
        %,every node near coord/.append style={rotate=90, anchor=west, font=\footnotesize}
        ]
\addplot [draw=red,pattern=horizontal lines] coordinates { (2,0.0000) (3,0.0402) (4,0.0660) (5,0.1246) (6,0.1434) (7,0.1478) (8,0.1777) (9,0.1801) (10,0.2024)};
\addplot [draw=green,pattern=crosshatch] coordinates { (2,0.0000) (3,0.1506) (4,0.2411) (5,0.2631) (6,0.2775) (7,0.3100) (8,0.3283) (9,0.3391) (10,0.3508)};
\addplot [draw=blue,pattern=north east lines] coordinates { (2,0.0000) (3,0.1156) (4,0.1850) (5,0.2246) (6,0.2743) (7,0.3158) (8,0.3452) (9,0.3406) (10,0.3471)};
\addplot [draw=black,pattern=north west lines] coordinates { (2,0.0000) (3,0.1837) (4,0.2388) (5,0.2668) (6,0.3146) (7,0.3363) (8,0.3490) (9,0.3570) (10,0.3560)};

        \end{axis}
        \end{tikzpicture}   
    }
    \subfloat[RA82]{
        \begin{tikzpicture}
        \begin{axis}[ybar, legend style={fill=none},
        width=0.49\linewidth,
        bar width=0.04cm,
        xlabel={$k$},
        ylabel={$\Delta ACC$}, 
        xtick=data,
        %ytick=data,
        enlarge y limits=true,
        legend pos=north west, legend entries={M1,M2,M3,M4}
        %enlarge y limits={upper,value=0.1},
        %,every node near coord/.append style={rotate=90, anchor=west, font=\footnotesize}
        ]
\addplot [draw=red,pattern=horizontal lines] coordinates { (2,0.0000) (3,0.0000) (4,0.0232) (5,0.0659) (6,0.0756) (7,0.1028) (8,0.1359) (9,0.1555) (10,0.2065)};
\addplot [draw=green,pattern=crosshatch] coordinates { (2,0.2343) (3,0.4221) (4,0.4144) (5,0.4501) (6,0.5162) (7,0.5067) (8,0.5273) (9,0.5518) (10,0.5846)};
\addplot [draw=blue,pattern=north east lines] coordinates { (2,0.0724) (3,0.1817) (4,0.2880) (5,0.3872) (6,0.4093) (7,0.4371) (8,0.4721) (9,0.4876) (10,0.5048)};
\addplot [draw=black,pattern=north west lines] coordinates { (2,0.4814) (3,0.4556) (4,0.4166) (5,0.3998) (6,0.3542) (7,0.3305) (8,0.3107) (9,0.2869) (10,0.2675)};
        \end{axis}
        \end{tikzpicture}   
    }\\
    \subfloat[Polbooks]{
        \begin{tikzpicture}
        \begin{axis}[ybar, legend style={fill=none},
        width=0.49\linewidth,
        bar width=0.04cm,
        xlabel={$k$},
        ylabel={$\Delta ACC$}, 
        xtick=data,
        %ytick=data,
        enlarge y limits=true,
        legend pos=north west, legend entries={M1,M2,M3,M4}
        %enlarge y limits={upper,value=0.1},
        %,every node near coord/.append style={rotate=90, anchor=west, font=\footnotesize}
        ]

\addplot [draw=red,pattern=horizontal lines] coordinates { (2,0.0000) (3,0.0080) (4,0.0254) (5,0.0545) (6,0.1003) (7,0.1372) (8,0.1690) (9,0.1997) (10,0.2128)};
\addplot [draw=green,pattern=crosshatch] coordinates { (2,0.0000) (3,0.0040) (4,0.0182) (5,0.0403) (6,0.0699) (7,0.0973) (8,0.1228) (9,0.1397) (10,0.1602)};
\addplot [draw=blue,pattern=north east lines] coordinates { (2,0.0000) (3,0.0083) (4,0.0273) (5,0.0520) (6,0.0838) (7,0.1064) (8,0.1254) (9,0.1403) (10,0.1465)};
\addplot [draw=black,pattern=north west lines] coordinates { (2,0.0000) (3,0.0076) (4,0.0180) (5,0.0457) (6,0.0734) (7,0.0890) (8,0.1062) (9,0.1168) (10,0.1261)};

        \end{axis}
        \end{tikzpicture}   
    }
    \subfloat[Football]{
        \begin{tikzpicture}
        \begin{axis}[ybar, legend style={fill=none},
        width=0.49\linewidth,
        bar width=0.04cm,
        xlabel={$k$},
        ylabel={$\Delta ACC$}, 
        xtick=data,
        %ytick=data,
        enlarge y limits=true,
        legend pos=north west, legend entries={M1,M2,M3,M4}
        %enlarge y limits={upper,value=0.1},
        %,every node near coord/.append style={rotate=90, anchor=west, font=\footnotesize}
        ]

\addplot [draw=red,pattern=horizontal lines] coordinates { (2,0.0000) (3,0.0000) (4,0.0000) (5,0.0000) (6,0.0000) (7,0.0000) (8,0.0007) (9,0.0021) (10,0.0037)};
\addplot [draw=green,pattern=crosshatch] coordinates { (2,0.0000) (3,0.0000) (4,0.0000) (5,0.0000) (6,0.0000) (7,0.0000) (8,0.0007) (9,0.0021) (10,0.0045)};
\addplot [draw=blue,pattern=north east lines] coordinates { (2,0.0000) (3,0.0000) (4,0.0000) (5,0.0000) (6,0.0000) (7,0.0000) (8,0.0010) (9,0.0035) (10,0.0087)};
\addplot [draw=black,pattern=north west lines] coordinates { (2,0.0000) (3,0.0000) (4,0.0000) (5,0.0000) (6,0.0000) (7,0.0000) (8,0.0017) (9,0.0046) (10,0.0089)};

        \end{axis}
        \end{tikzpicture}   
    }
    \caption{The value of $\Delta ACC$ for different datasets and models in $k=2\ldots 10$. }
    \label{fig:DACC}
\end{figure}

\end{document}
فایل‌های پیوست
سوال شده بهمن 25, 1396 توسط رضا (100 امتیاز)

1 پاسخ

0 رای
 
بهترین پاسخ

برای اینکه یدونه‌ای بشه از کد زیر استفاده کنید:

\pgfplotsset{compat=newest,
    /pgfplots/ybar legend/.style={
        /pgfplots/legend image code/.code={%
            \draw[##1,/tikz/.cd,yshift=-0.25em]
            (0cm,0cm) rectangle (3pt,0.8em);},
    },
}

قسمت دوم سؤال

برای اینکه یه legend داشته باشید، من کدتون رو تغییر دادم و از groupplot استفاده کردم. فک کنم بهتر از روشی باشه که شما استفاده کردید.
کد:

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{patterns}
\usepgfplotslibrary{groupplots}
\usepackage{subfig} % Para hacer los subfigure
\usepackage{float}%Posicionamiento fijo con "[H]"
\pgfplotsset{compat=newest,
    /pgfplots/ybar legend/.style={
        /pgfplots/legend image code/.code={%
            \draw[##1,/tikz/.cd,yshift=-0.25em]
            (0cm,0cm) rectangle (3pt,0.8em);},
    },
}

\begin{document}
\begin{figure}[htbp]
\centering
\begin{tikzpicture}
    \begin{groupplot}[%
        group style = {group size=2 by 2, horizontal sep = 50pt, vertical sep=2cm},
        ybar, legend style={fill=none},
        width=0.49\linewidth,
        xlabel={$k$},
        ylabel={$\Delta ACC$}, 
        xtick=data,
        enlarge y limits=true,
        legend style = { column sep = 10pt, legend columns = -1, legend to name = grouplegend},
        legend pos=north west, legend entries={M1,M2,M3,M4}%
    ]
    \nextgroupplot[bar width=0.04cm]
    \addplot [draw=red,pattern=horizontal lines] coordinates { (2,0.0000) (3,0.0402) (4,0.0660) (5,0.1246) (6,0.1434) (7,0.1478) (8,0.1777) (9,0.1801) (10,0.2024)};
    \addplot [draw=green,pattern=crosshatch] coordinates { (2,0.0000) (3,0.1506) (4,0.2411) (5,0.2631) (6,0.2775) (7,0.3100) (8,0.3283) (9,0.3391) (10,0.3508)};
    \addplot [draw=blue,pattern=north east lines] coordinates { (2,0.0000) (3,0.1156) (4,0.1850) (5,0.2246) (6,0.2743) (7,0.3158) (8,0.3452) (9,0.3406) (10,0.3471)};
    \addplot [draw=black,pattern=north west lines] coordinates { (2,0.0000) (3,0.1837) (4,0.2388) (5,0.2668) (6,0.3146) (7,0.3363) (8,0.3490) (9,0.3570) (10,0.3560)};

    \nextgroupplot[bar width=0.04cm]
    \addplot [draw=red,pattern=horizontal lines] coordinates { (2,0.0000) (3,0.0000) (4,0.0232) (5,0.0659) (6,0.0756) (7,0.1028) (8,0.1359) (9,0.1555) (10,0.2065)};
    \addplot [draw=green,pattern=crosshatch] coordinates { (2,0.2343) (3,0.4221) (4,0.4144) (5,0.4501) (6,0.5162) (7,0.5067) (8,0.5273) (9,0.5518) (10,0.5846)};
    \addplot [draw=blue,pattern=north east lines] coordinates { (2,0.0724) (3,0.1817) (4,0.2880) (5,0.3872) (6,0.4093) (7,0.4371) (8,0.4721) (9,0.4876) (10,0.5048)};
    \addplot [draw=black,pattern=north west lines] coordinates { (2,0.4814) (3,0.4556) (4,0.4166) (5,0.3998) (6,0.3542) (7,0.3305) (8,0.3107) (9,0.2869) (10,0.2675)};

    \nextgroupplot[bar width=0.04cm]
    \addplot [draw=red,pattern=horizontal lines] coordinates { (2,0.0000) (3,0.0080) (4,0.0254) (5,0.0545) (6,0.1003) (7,0.1372) (8,0.1690) (9,0.1997) (10,0.2128)};
    \addplot [draw=green,pattern=crosshatch] coordinates { (2,0.0000) (3,0.0040) (4,0.0182) (5,0.0403) (6,0.0699) (7,0.0973) (8,0.1228) (9,0.1397) (10,0.1602)};
    \addplot [draw=blue,pattern=north east lines] coordinates { (2,0.0000) (3,0.0083) (4,0.0273) (5,0.0520) (6,0.0838) (7,0.1064) (8,0.1254) (9,0.1403) (10,0.1465)};
    \addplot [draw=black,pattern=north west lines] coordinates { (2,0.0000) (3,0.0076) (4,0.0180) (5,0.0457) (6,0.0734) (7,0.0890) (8,0.1062) (9,0.1168) (10,0.1261)};

    \nextgroupplot[bar width=0.04cm]
    \addplot [draw=red,pattern=horizontal lines] coordinates { (2,0.0000) (3,0.0000) (4,0.0000) (5,0.0000) (6,0.0000) (7,0.0000) (8,0.0007) (9,0.0021) (10,0.0037)};
    \addplot [draw=green,pattern=crosshatch] coordinates { (2,0.0000) (3,0.0000) (4,0.0000) (5,0.0000) (6,0.0000) (7,0.0000) (8,0.0007) (9,0.0021) (10,0.0045)};
    \addplot [draw=blue,pattern=north east lines] coordinates { (2,0.0000) (3,0.0000) (4,0.0000) (5,0.0000) (6,0.0000) (7,0.0000) (8,0.0010) (9,0.0035) (10,0.0087)};
    \addplot [draw=black,pattern=north west lines] coordinates { (2,0.0000) (3,0.0000) (4,0.0000) (5,0.0000) (6,0.0000) (7,0.0000) (8,0.0017) (9,0.0046) (10,0.0089)};

    \end{groupplot}
    \node at ($(group c2r2) + (-3,8cm)$) {\ref{grouplegend}};
\end{tikzpicture}   
\caption{The value of $\Delta ACC$ for different datasets and models in $k=2\ldots 10$. }
\label{fig:DACC}
\end{figure}

\end{document}

خروجی:
enter image description here

پاسخ داده شده بهمن 26, 1396 توسط Hossein_A (48 امتیاز)
انتخاب شده بهمن 26, 1396 توسط رضا
...