When I plot my data with linear Y-axis (not logarithmic), chart is good, as below:
But when I use logarithmic scale for Y-axis, my chart looks upside-down:
chart1.ChartAreas[0].CursorY.IsUserEnabled = true;
chart1.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
chart1.ChartAreas[0].AxisY.ScaleView.Zoomable = true;
chart1.ChartAreas[0].AxisY.ScrollBar.Enabled = true;
chart1.ChartAreas[0].AxisY.ScrollBar.IsPositionedInside = true;
chart1.ChartAreas[0].CursorY.Interval = 1e-10;//zoom resolution threshold
/////////////////when I added following line, chart becomes upside-down:
chart1.ChartAreas[0].AxisY.IsLogarithmic = true;
using (StreamReader reader = new StreamReader(
"Frequencies(Hz)_and_corresponding_SingularValues.txt"
))
{
string line;
while ((line = reader.ReadLine()) != null)
{
string[] tokens = line.Split(new char[] { '\t' });
x = Convert.ToDouble(tokens[0]);
y = Convert.ToDouble(tokens[1]);
chart1.Series["Series1"].Points.AddXY(x, y);
}
}
Upside-down chart is shown below, does anybody know why it gets flipped:
Another question: when plotting with logarithmic scale, what is the best way to avoid exceptions due to zero/negative data without modifying original data?
EDIT: I thought maybe color of background and color of chart series are switched, therefore I added following line to test it, but chart is still upside-down:
chart1.Series["Series1"].Color = Color.Blue;
ln(x) < 0
ifx < 1
. You can setchart1.ChartAreas[0].AxisY.IsReversed = true
to invert the asix. – Dmitryx
is smaller than some threshold value thenlog(x)
andln(x)
would be negative, I forgot about it. However when I changed chart type, chart looks good now. – user3405291