Sorry if this doesn't seem well-researched, but I couldn't find the answer anywhere.
Is there a way to reverse an axis in a TikZ \datavisualization
? Concretely, I want to reverse the y
axis in a cartesian system, so that positive points down.
Clarification: I didn't express myself correctly. Basically I only want to get a y
axis in which positive is down and negative is
up. But that's not simply putting the $y$
label at the bottom; I
actually want positive to be down and the arrow to point down. The
"aiming for" image is confusing because there are no tick marks. But
if I added them, the y axis would show 1 (and not -1). Of course, then
the whole graph would appear on the opposite side. But I could easily
change the csv
files to reverse all of the y coordinates. In fact, the
only reason I put negative y coordinates in the csv files was
precisely because I didn't know how to "properly" flip the axis, but
the original data is all positive (both in x
and y
). Sorry for the confusion.
@whatisit gave the solution straight away, which was yscale=-1
.
Now the only problem is getting the correct anchoring of tick
marks/labels. Again, sorry for the confusion.
From what I've gathered from this question, when manually specifying an axis
you can use the key y dir=reverse
. But I haven't found any equivalent way using the \datavisualization
library. I'm using the school book axes
system.
Here's what I've tried:
\datavisualization [school book axes,
y dir=reverse]
\datavisualization [school book axes,
all axes={y dir=reverse}]
\datavisualization [school book axes,
y axis=reverse]
\datavisualization [school book axes,
y={dir=reverse}]
MWE (updated)
This is what I'm working on. I've stripped down the preamble to a minimum.
\documentclass[11pt, a4paper]{article}
\usepackage[margin=2.5cm]{geometry}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{datavisualization}
\usepackage{filecontents}
\begin{filecontents}{1.csv}
0, 0
0.100000, 0.102985
0.200000, 0.284078
0.300000, 0.431294
0.800000, 0.886640
0.900000, 0.946767
1.000000, 1.000000
\end{filecontents}
\begin{filecontents}{2.csv}
0, 0
0.104298, 0.280000
0.213643, 0.440000
0.300496, 0.540000
0.709127, 0.860000
0.820097, 0.920000
0.904455, 0.960000
1.000000, 1.000000
\end{filecontents}
\begin{filecontents}{3.csv}
0, 0
0.105170, 0.292368
0.205373, 0.440170
0.325606, 0.575855
0.435812, 0.676699
0.502248, 0.729587
0.663074, 0.838455
0.760352, 0.893359
0.871594, 0.947572
1.000000, 1.000000
\end{filecontents}
\begin{document}
\begin{tikzpicture}[>=stealth]
\datavisualization data group {methods} = {
data [set=m1, read from file={1.csv}]
data [set=m2, read from file={2.csv}]
data [set=m3, read from file={3.csv}]
};
\datavisualization [school book axes,
visualize as scatter/.list={m1,m3,m2},
all axes={unit length=8cm},
x axis={label=$x$},
y axis={label=$y$},
yscale=-1,
style sheet={vary hue},
style sheet={cross marks},
data/headline={x,y}]
data group {methods};
\end{tikzpicture}
\end{document}
The complete CSV files can be found here.
Current output (updated)
Note: as @whatisit suggested, I'm using yscale=-
. The problem now is how to change the label/tick anchoring.
What I'm aiming for
Something like this:
\begin{tikzpicture}[>=stealth, scale=6]
\coordinate (X) at (1.3, 0);
\coordinate (Y) at (0, -1.1);
\draw[black!30, very thin] (X) grid (Y);
\draw[black!5, very thin, step=0.2] (X) grid (Y);
\draw[->, very thick] (0, 0) -- node[very near end, anchor=south west] {\Large$x$} (X);
\draw[->, very thick] (0, 0) -- node[very near end, anchor=north east] {\Large$y$} (Y);
\draw[blue, loosely dotted, very thick] plot file {1.data};
\draw[purple, loosely dotted, ultra thick] plot file {2.data};
\draw[red, loosely dotted, very thick] plot file {3.data};
\end{tikzpicture}
Here 1.data
, 2.data
and 3.data
are exactly like the CSV files but separated by spaces instead of commas.
\begin{tikzpicture}[yscale=-1]
? This will flip all y coordinates to the opposite sign. (You can also use this option in\datavisualization
instead)anchor
\documentclass
, end with\end{document}
, can be compiled and illustrate the point you will get very quickly answers and also upvotes to your question.1.csv
,2.csv
and3.csv
are still missing. You can include them usingfilecontents
, which makes it more convenient for others. And even if I add them, the document cannot be compiled. Further, why are you loadingpgfplots
here? You do not seem to use it. Of course, if you use it, you can easily reverse axes.1.csv
,2.csv
and3.csv
were placeholder names. I tried compiling and it works fine for me. I'm hesitant to putfilecontents
because the files are large.