Remove first and last axis tick in pgfplots - tikz

I want to plot a coordinate system like this and I want to get rid of the first and the last tick of the x-axis and the y-axis. Like in my example I also don't want tick labels at the begin and the end of every axis.
How can I get rid of the first and the last tick of every axis?
This is my code:
\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz,pgfplots}
\usepackage{helvet}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=newest, width=7cm, height=7cm,
every x tick label/.append style={font=\scriptsize\sffamily, yshift=0.2ex},
every y tick label/.append style={font=\scriptsize\sffamily, xshift=0.2ex}}
\begin{document}
\begin{tikzpicture}[font=\small\sffamily]
\begin{axis}[ clip=true,
xmin=-3, xmax=6,
ymin=-4, ymax=5,
xtick={-3,...,6},
xticklabels={,-2,-1,,1,2,3,4,5,},
ytick={-4,...,5},
yticklabels={,-3,-2,-1,,1,2,3,4,},
minor tick num=1,
axis lines=middle,
xlabel=\textbf{x},
ylabel=\textbf{y},
xmajorgrids=true,
xminorgrids=true,
ymajorgrids=true,
yminorgrids=true,
axis line style={line width=1pt},
every x tick/.style={color=black, thick},
every y tick/.style={color=black, thick}
]
\draw[line width=.5pt](current axis.south west)rectangle(current axis.north east);
\end{axis}
\end{tikzpicture}
\end{document}

Quick and dirty hack:
\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz,pgfplots}
\usepackage{helvet}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=newest, width=7cm, height=7cm,
every x tick label/.append style={font=\scriptsize\sffamily, yshift=0.2ex},
every y tick label/.append style={font=\scriptsize\sffamily, xshift=0.2ex}}
\begin{document}
\begin{tikzpicture}[font=\small\sffamily]
\begin{axis}[ clip=true,
xmin=-2.99, xmax=5.99,
ymin=-3.99, ymax=4.99,
xtick={-3,...,6},
xticklabels={,-2,-1,,1,2,3,4,5,},
ytick={-4,...,5},
yticklabels={,-3,-2,-1,,1,2,3,4,},
minor tick num=1,
axis lines=middle,
xlabel=\textbf{x},
ylabel=\textbf{y},
xmajorgrids=true,
xminorgrids=true,
ymajorgrids=true,
yminorgrids=true,
axis line style={line width=1pt},
every x tick/.style={color=black, thick},
every y tick/.style={color=black, thick}
]
\draw[line width=.5pt](current axis.south west)rectangle(current axis.north east);
\end{axis}
\end{tikzpicture}
\end{document}

Related

To color the two regions separated by a parabolic function with different colors respectively using tikz (The function as the boundary)

Could someone give some suggestions? I want to color the two areas of the rectangle with blue and yellow respectively, as shown in the picture. The function is as the boundary between the two regions.
Here is my code and expected result.
\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{scope}[shorten >=1pt,-,draw=black!80, node distance=\layersep]
\begin{axis}[
width=8.8cm,
enlargelimits=false,
axis on top,
point meta=explicit,
height=6.5cm,
xlabel={},
ylabel={},
xtick=\empty,
ytick=\empty,
xmin=-8,
xmax=8,
ymin=-10,
ymax=1,
xlabel={\large $x$},
ylabel={\large $y$},
%ylabel style={yshift=0.0cm},
yticklabels={},
xticklabel style = {font=\large,yshift=0.0ex},
colorbar style={
font =\Large
},
]
\addplot [thick]{-0.8*(x-1)^2};
\end{axis}
\end{scope}
\end{tikzpicture}
\end{document}
\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{scope}[shorten >=1pt,-,draw=black!80, node distance=\layersep]
\begin{axis}[
width=8.8cm,
enlargelimits=false,
axis on top,
point meta=explicit,
height=6.5cm,
xlabel={},
ylabel={},
xtick=\empty,
ytick=\empty,
xmin=-8,
xmax=8,
ymin=-10,
ymax=1,
xlabel={\large $x$},
ylabel={\large $y$},
%ylabel style={yshift=0.0cm},
yticklabels={},
xticklabel style = {font=\large,yshift=0.0ex},
colorbar style={
font =\Large
},
axis background/.style={fill=yellow},
]
\addplot [thick,fill=blue]{-0.8*(x-1)^2};
\end{axis}
\end{scope}
\end{tikzpicture}
\end{document}

Add 0.5x0.5 degree grid on drawing of country outline

How do I draw a 0.5 degree x 0.5 degree grid over the country map in a MATLAB figure?
The code below gives me a gridded figure but not with 0.5x0.5 degree spacing.
borders('Iran Islamic Republic of')
grid on
ax.GridLineStyle = '-';
Can anyone tell me how to add 0.5x0.5 grid along x and y-axis to this figure?
The borders function is taken from the MATLAB File Exchange
You can use xticks() and yticks() functions (matlab tutorial). Your code should be something like:
borders('Iran Islamic Republic of')
grid on
ax.GridLineStyle = '-';
% Modify the X and Y ticks positions
xticks([44:.5:65]);
yticks([25:.5:40]);
This creates ticks every 0.5 degrees (from degree 44 until 65 in x, and from 25 to 40 in y). If the tick labels are overlaping, you can delete some. For example for the x-axis:
%Delete some labels, otherwise overcrowded
xlabels = xticklabels();
for i=2:2:length(xticks())
xlabels(i)={''};
end
xticklabels(xlabels)

How to have vertical x labels?

Soft Question: How to edit the x label in a bar graph to be vertical in Matlab?
Here is an example of the x-axis I would like to have
You have to get the handle of the axis first. Then you can edit the X axis Tick rotation property which is zero by default. By setting this parameter to 90, it will rotate your x-axis like your picture.
h = gca; % handle for current axis
h.XTickLabelRotation = 90; % rotate the tick label

JAVAFX CHARTS: Setting origin point on category axis

I am in need to add a zero point for category axis in javafx line chart. In the image I want some "T0" to represent the zero mark of origin on the x axis, so that I can mark point on y axis as on the chart.
sample line chart ( looks like bar chart !)
I'm not completely clear what you're asking, but if you want the pixel coordinates of the left end of the x-axis, you can do
Category xAxis = ... ;
// ...
double leftEnd = xAxis.getDisplayPosition(value0) - xAxis.getCategorySpacing();
where value0 is the x-value of the first data point.

draw vertical lines at regular intervals in a rectangle in matlab

I need to draw vertical lines at regular intervals in a rectangular box. this is what i have used so far:
xmin=000;
xmax=70000;
ymin=0;
ymax=1000;
line1Val=900;
line2Val=600;
line3Val=300;
xlim([xmin xmax])
ylim([ymin ymax])
xl=get(gca,'XLim');
line(xl,[line1Val line1Val],'Color','y');
line(xl,[line2Val line2Val],'Color','y');
line(xl,[line3Val line3Val],'Color','y');
hold on ;
rectangle('Position',[120000,900,(280000-120000),37],'faceColor','k')
so the width of the rectangle is 160000 units i want to divide this into 4 , where the vertical line is of a different color(say red) and the height of the line is 37 units.
any ideas on how i can draw this without drawing 4 rectangles whose edges are red and are filled with black color.
You could use the parameters xstart,ystart,width and height for drawing your rectangle:
rectangle('Position',[xstart,ystart,width,height],'faceColor','k');
After that, you could determine the line positions in a loop and simply draw these lines:
for i = 1:3
x = xstart+i*width/4;
line([x x],[ystart ystart+height],'Color','r');
end
If you want a red line at the start and end of the rectangle, let i = 0:4.