# Problems with bar plot style and size

I want to make my plot look like the one in the screenshot. Same colors, same style and position of the legends and the dotted grid in the background!

One more bar will be added, though

Ideally it would look something like this(3 bars only):

 \documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\definecolor{curlyblue}{RGB}{39,26,115}
\definecolor{curlygreen}{RGB}{48,172,140}
\pgfplotsset{width=9cm,compat=1.8}
\pgfplotsset{
/pgfplots/bar cycle list/.style={/pgfplots/cycle list={
{black,fill=curlyblue,mark=none},
{black,fill=curlygreen,mark=none},
{black,fill=yellow,mark=none},
}, }}

\begin{document}
\begin{tikzpicture}[font=]
\begin{axis}[
ybar,
enlargelimits=0.09,
legend style={at={(0.75,0.95)},
anchor=north,legend columns=1},
ylabel={RMSE},
symbolic x coords={50,100,150,200,250},
xtick=data,
nodes near coords,
nodes near coords align={vertical},
]

\addplot coordinates {(50,0.9359) (100,0.9351) (150,0.9361) (200,0.9376) (250,0.9386) };
\addplot coordinates {(50,0.9324) (100,0.9294) (150,0.9291) (200,0.9290) (250,0.9289) };
\addplot coordinates {(50,0.9297) (100,0.9281) (150,0.9280) (200,0.9280) (250,0.9280) };
\legend{Cosine,Pearson,PearsonBL}
\end{axis}
\end{tikzpicture}
\end{document}


I also tried this but it does not work either:

\documentclass{standalone}
\usepackage{pgfplots, pgfplotstable}
\pgfplotsset{compat=1.15}

\begin{filecontents}{data.csv}
A,  B,  C,  D
50,  0.9359, 0.9324, 0.9297
100, 0.9351, 0.9294, 0.9281
150, 0.9361, 0.9291, 0.9280
200, 0.9376, 0.9290, 0.9280
250, 0.9386, 0.9289, 0.9280
%   300, 0.9359, 0.9359, 0.9359
%   350, 0.9359, 0.9359, 0.9359
%   350, 0.9359, 0.9359, 0.9359
\end{filecontents}

\begin{document}
\begin{tikzpicture}
\begin{axis}[width=11cm,
ybar,
bar width=7pt,
xlabel={},
xtick=data,
xticklabels from table={\datatable}{A},
ymajorgrids,
legend pos=north west
]
\legend{Cosine, Pearson, PearsonBL}
\end{axis}
\end{tikzpicture}
\end{document}


HERE ARE THE TRUE COORDINATES:

\addplot[black,fill=blue1] coordinates {
(50,0.9359) (100,0.9351) (150,0.9361) (200,0.9376) (250,0.9386) (300,0.9391) (350,0.9393) (400,0.9395)
};

(50,0.9324) (100,0.9294) (150,0.9291) (200,0.9290) (250,0.9289) (300,0.9289) (350,0.9289) (400,0.9289)};

(50,0.9297) (100,0.9281) (150,0.9280) (200,0.928) (250,0.928) (300,0.928) (350,0.928) (400,0.9280)
};

• Could you please add some clarifications to your question about what exactly your problem is: Is it the position and style of the legend, is ist the colors, is it the numbers that appear above the bars, is it the y-axis labels, is it the dotted grid in the background...? Oct 3, 2019 at 8:55
• I want to make my plot look like the one in the screenshot. Same colors, same style and position of the legends and the dooted grid in the background! Oct 3, 2019 at 8:59
• So, basically, everything, I mentioned. Since your screenshot of the desired output only shows two sets of bars, (=two colors), what's the desired color of the third set? Oct 3, 2019 at 9:00
• A gray good be awesome! Or whatever one you consider that matches the triplet Oct 3, 2019 at 9:01

Probably the following is closer to what you wanted to achieve:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}

%% Define the colors used for the bars %%
\definecolor{myblue}{RGB}{0,0,143}
\definecolor{myred}{RGB}{128,0,0}
\definecolor{mygray}{RGB}{128,128,128}

\pgfplotsset{width=9cm,compat=1.8}

%% Set up for the bar chart, mostly unchanged despite of colors %%
\pgfplotsset{/pgfplots/bar cycle list/.style={
/pgfplots/cycle list={
{black,fill=myblue,mark=none},
{black,fill=myred,mark=none},
{black,fill=mygray,mark=none},
}, }}

%% Adding the dotted grid %%
\pgfplotsset{grid style = {
dash pattern = on 0.05mm off 1mm,
line cap = round,
black,
line width = 0.5pt
}}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar,
%% related to legend, draw=none removes the border, anchor= north east places legend in upper right corner%%
legend style={draw=none,at={(1,1)},anchor=north east,legend columns=1},
legend cell align={left},
%% style of y axis labels, precision=3 adds a third decimal place, fixed zerofill adds otherwise missing zeros (e.g. 0.93 vs. 0.930)%%
y tick label style={/pgf/number format/.cd,precision=3,fixed zerofill},
ylabel={RMSE},
%% ymax makes sure that the legend does not overlap with the blue 250 bar
ymax=0.941,
%% adds sme horizontal white space between the left- and right-most bar and hte corresponding y axis%%
enlarge x limits=0.15,
%% adds the grid that we defined earlier%%
grid,
%% makes sure that the ticks of the upper x axis stay inside the plot
xtick align=inside
]

\addplot coordinates {(50,0.9359) (100,0.9351) (150,0.9361) (200,0.9376) (250,0.9386) };
\addplot coordinates {(50,0.9324) (100,0.9294) (150,0.9291) (200,0.9290) (250,0.9289) };
\addplot coordinates {(50,0.9297) (100,0.9281) (150,0.9280) (200,0.9280) (250,0.9280) };
\legend{Cosine,Pearson,PearsonBL}
\end{axis}
\end{tikzpicture}

\end{document}


Changes I have done in comparison to the original code:

• Color of the bars: In order to add the desired colors to the bars, I have changed the origonal \definecolor commands to match the colors in the screenshot. I have also added a third, gray color for the third set of bars.
• Dotted grid: The code for the dotted grid is borrowed from Jake's answer to Change grid line dash pattern such that grid intersections look uniform
• Legend style: To remove the box around the legend, I have used the draw=noneoption. To place the legend in the upper right corner, I have used anchor=north east and to left align the legend entries, I have used legend cell align={left}. (Inspiration for these options came from Harry49's answer to How to align the content of the legend to the left instead of default centre? and from Matthew Leingang's answer to Removing legend box (border) in pgfplots). I have also added y max in order to prevent the legend from overlapping with the large blue bar of the rightmost set.
• Number format of y axis: To change the number format of the y axis to include an additional decimal place, I have used y tick label style={/pgf/number format/.cd,precision=3,fixed zerofill}, that was inspired by Jake's answer to pgfplots - number format on axis. If you prefer 0.930 being displayed without the trailing 0(as in 0.93), simply remove fixed zerofill.
• Horizontal white space: To add some horizontal white space between the leftmost and the rigtmost column and theis respective y axis, I have used enlarge x limits=0.15, as suggested by Jake in their answer to Insert space between axis and plot in pgfplots.
• Position of upper x axis ticks: In order to place the ticks of the upper x axis below the axis (inside of the plot) instead of above, I have added xtick align=inside as shown by Jake in the answer to Pgfplots ybar option draws tickmarks outside the plot area.
• Numbers above bars: Lastly, I have removed nodes near coords to get rid of the numbers that were displayes above the corresponding bars.

Here is the adjsted MWE for your actual data. I have adjusted the color names to match the definitions, changed the values of ymax and enlarge x limits and added added bar width=5pt, to prevent the individual sets of bars from overlapping:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}

%% Define the colors used for the bars %%
\definecolor{myblue}{RGB}{0,0,143}
\definecolor{myred}{RGB}{128,0,0}
\definecolor{mygray}{RGB}{128,128,128}

\pgfplotsset{width=9cm,compat=1.8}

%% Adding the dotted grid %%
\pgfplotsset{grid style = {
dash pattern = on 0.05mm off 1mm,
line cap = round,
black,
line width = 0.5pt
}}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar,
bar width=5pt,
%% related to legend, draw=none removes the border, anchor= north east places legend in upper right corner%%
legend style={draw=none,at={(1,1)},anchor=north east,legend columns=1},
legend cell align={left},
%% style of y axis labels, precision=3 adds a third decimal place, fixed zerofill adds otherwise missing zeros (e.g. 0.93 vs. 0.930)%%
y tick label style={/pgf/number format/.cd,precision=3,fixed zerofill},
ylabel={RMSE},
%% ymax makes sure that the legend does not overlap with the blue 250 bar
ymax=0.943,
%% adds sme horizontal white space between the left- and right-most bar and hte corresponding y axis%%
enlarge x limits=0.1,
%% adds the grid that we defined earlier%%
grid,
%% makes sure that the ticks of the upper x axis stay inside the plot
xtick align=inside
]

(50,0.9359) (100,0.9351) (150,0.9361) (200,0.9376) (250,0.9386) (300,0.9391) (350,0.9393) (400,0.9395)};

(50,0.9324) (100,0.9294) (150,0.9291) (200,0.9290) (250,0.9289) (300,0.9289) (350,0.9289) (400,0.9289)};

• Just in case , for the labels:  \pgfplotsset{legend image code/.code={\draw [#1] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);},} Oct 3, 2019 at 9:34